{"id":6761,"date":"2021-05-24T10:43:02","date_gmt":"2021-05-24T16:43:02","guid":{"rendered":"http:\/\/gregsowell.com\/?p=6761"},"modified":"2021-05-24T10:43:02","modified_gmt":"2021-05-24T16:43:02","slug":"using-collections-with-ansible-tower-ansible-control","status":"publish","type":"post","link":"https:\/\/gregsowell.com\/?p=6761","title":{"rendered":"Using Collections With Ansible Tower\/Ansible Control"},"content":{"rendered":"<p><a href=\"https:\/\/www.ansible.com\/blog\/getting-started-with-ansible-collections\">Collections<\/a> are the new hotness for ansible, so you should start adjusting to it now&#8230;that means I&#8217;ll have to start converting my playbooks little by little now.  That&#8217;s because ansible 2.9 allows for both standard modules and collections to work in tandem.  So do the thing if you haven&#8217;t already.<\/p>\n<p>You have multiple options when trying to install collections into your tower environment, and I&#8217;m going to cover a couple here.<\/p>\n<h2>Manual collection install<\/h2>\n<p>If you are going to manually install these files from the CLI, keep in mind that <strong>Tower runs as the AWX user<\/strong>, so you will need to <strong>su awx before doing most of these installs<\/strong>.<br \/>\nFirst you can <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/collections_using.html#installing-collections-with-ansible-galaxy\">pull collections straight from Ansible galaxy<\/a>.<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">ansible-galaxy collection install my_namespace.my_collection<\/code><\/pre>\n<p>You can also download the archive file and do an offline install:<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">ansible-galaxy collection install my_namespace-my_collection-1.0.0.tar.gz -p .\/collections<\/code><\/pre>\n<p>You can download certified collections via the automation hub(it allows you to grab them as archives right off the cloud.redhat.com site).  After that the install process is just the same.<\/p>\n<h2>Automatic collection install<\/h2>\n<p>The best way to automatically <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/collections_using.html#install-multiple-collections-with-a-requirements-file\">pull collections is via a requirements file<\/a>.  <\/p>\n<p>First, in your git repository(or other SCM system) create a folder called &#8220;collections&#8221; and add a file inside named &#8220;requirements.yml&#8221;<br \/>\nSo I wanted to dynamically pull the Arista EOS collection so I did it as follows(\/collections\/requirements.yml):<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">---\r\ncollections:\r\n# Install the Arista EOS collection\r\n- arista.eos<\/code><\/pre>\n<p>Now when I run the playbook it will reach out to the repository in question and pull the content.<br \/>\nKeep in mind that it doesn&#8217;t fully install the collection.  I can&#8217;t create a new repo with playbooks and start using that collection without either a manual install or a requirements file.  It&#8217;s for this reason that in my lab environment I simply do a manual install so I can use it in all of my playbooks without keeping track.<\/p>\n<p>If you are using certified content and you want to <a href=\"https:\/\/goetzrieger.github.io\/ansible-collections\/6-automation-hub-and-galaxy\/\">pull directly from the Automation hub, look at this documentation; it walks through the settings required<\/a>.<br \/>\nIn newer versions of Tower\/control the &#8220;Primary Galaxy Server&#8221; options are no longer present and that portion will be completed via <a href=\"https:\/\/www.youtube.com\/watch?v=YiwxPFcOWvE&#038;ab_channel=RedHatAnsibleAutomation\">custom credentials as shown in this video<\/a>.<br \/>\nHere&#8217;s the screen shots from my machine:<br \/>\nFirst I created two credentials:<br \/>\n<a href=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_1-300x102.jpg\" alt=\"\" width=\"300\" height=\"102\" class=\"aligncenter size-medium wp-image-6765\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_1-300x102.jpg 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_1-768x261.jpg 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_1.jpg 937w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The first connects to the automation hub:<br \/>\n<a href=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_2-300x99.jpg\" alt=\"\" width=\"300\" height=\"99\" class=\"aligncenter size-medium wp-image-6766\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_2-300x99.jpg 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_2-768x253.jpg 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_2-1024x338.jpg 1024w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_2.jpg 1306w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nGalaxy Server URL:<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">https:\/\/cloud.redhat.com\/api\/automation-hub\/<\/code><\/pre>\n<p>Auth Server URL:<\/p>\n<pre class=\"gs-code\"><code class=\"language-plaintext\">https:\/\/sso.redhat.com\/auth\/realms\/redhat-external\/protocol\/openid-connect\/token<\/code><\/pre>\n<p>I then create a credential to connect to the standard public galaxy servers:<br \/>\n<a href=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_3.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_3-300x91.jpg\" alt=\"\" width=\"300\" height=\"91\" class=\"aligncenter size-medium wp-image-6767\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_3-300x91.jpg 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_3-768x233.jpg 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_3-1024x311.jpg 1024w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_3.jpg 1407w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I now set the Tower\/control server to use these creds:<br \/>\n<a href=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_4.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_4-300x217.jpg\" alt=\"\" width=\"300\" height=\"217\" class=\"aligncenter size-medium wp-image-6768\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_4-300x217.jpg 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_4-768x555.jpg 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_4.jpg 833w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<a href=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_5.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_5-300x141.jpg\" alt=\"\" width=\"300\" height=\"141\" class=\"aligncenter size-medium wp-image-6769\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_5-300x141.jpg 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_5-768x362.jpg 768w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_5-1024x482.jpg 1024w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_5.jpg 1104w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nThe order in which you select them is the order in which the server will check for download.  In my case I want to ensure that my automation hub link is set first, so it will check there, then fall back to checking galaxy.  That means I&#8217;ll unselect them both, then add them back in the correct order:<br \/>\n<a href=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_6.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_6-300x227.jpg\" alt=\"\" width=\"300\" height=\"227\" class=\"aligncenter size-medium wp-image-6770\" srcset=\"https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_6-300x227.jpg 300w, https:\/\/gregsowell.com\/wp-content\/uploads\/2021\/05\/Screenshot_6.jpg 623w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Good luck and happy automating!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Collections are the new hotness for ansible, so you should start adjusting to it now&#8230;that means I&#8217;ll have to start converting my playbooks little\u2026<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"class_list":["post-6761","post","type-post","status-publish","format-standard","hentry","category-ansible"],"_links":{"self":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/6761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6761"}],"version-history":[{"count":4,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/6761\/revisions"}],"predecessor-version":[{"id":6771,"href":"https:\/\/gregsowell.com\/index.php?rest_route=\/wp\/v2\/posts\/6761\/revisions\/6771"}],"wp:attachment":[{"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gregsowell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}