{"id":568,"date":"2020-08-28T14:21:14","date_gmt":"2020-08-28T13:21:14","guid":{"rendered":"https:\/\/zed-network.fr\/?p=568"},"modified":"2020-08-28T14:22:35","modified_gmt":"2020-08-28T13:22:35","slug":"how-to-use-the-open-source-ansible-tower-awx","status":"publish","type":"post","link":"https:\/\/zed-network.fr\/?p=568","title":{"rendered":"How to use the open source Ansible Tower (AWX)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Install AWX<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">AWX is a GUI tool for Ansible. In this article we will deploy AWX on a Kubernetes cluster. We also have GitLab-CE to store playbooks and manage the version.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The first step is to clone AWX:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git clone https:\/\/github.com\/ansible\/awx.git<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then you need to complete the inventory file. AWX will be deployed with Ansible. You also need to have Ansible, Helm and kubectl installed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The installation is explained here: https:\/\/github.com\/ansible\/awx\/blob\/devel\/INSTALL.md<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You need to modify some variables to describe which K8s cluster you will use:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>c01-m1 is the kubernetes master node<\/li><li>kubernetes-admin@kubenetes is the context name<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">c01-m1 ansible_python_interpreter=\"\/usr\/bin\/env python3\"\n[..]\nkubernetes_context=kubernetes-admin@kubernetes\nkubernetes_namespace=awx\nkubernetes_web_svc_type=LoadBalancer<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now you will be able to deploy AWX on your cluster with Ansible :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ansible-playbook -i inventory install.yml<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check your deployment:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubectl get svc,pod,pvc -n awx<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"224\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-25-1024x224.png\" alt=\"\" class=\"wp-image-569\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-25-1024x224.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-25-300x66.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-25-768x168.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-25-1536x335.png 1536w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-25.png 1868w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The default credential is admin \/ password.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GitLab-CE<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now you need a Git repository with one playbook.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can easily deploy Gitlab-ce with Docker inside Kubernetes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: gitlab-ce\n  labels:\n    app: gitlab-ce\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: gitlab-ce\n  template:\n    metadata:\n      labels:\n        app: gitlab-ce\n    spec:\n      containers:\n      - name: gitlab-ce\n        image: gitlab\/gitlab-ce\n        ports:\n        - containerPort: 22\n        - containerPort: 80\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: svc-gitlab-ce\n  labels:\n    app: gitlab-ce\nspec:\n  ports:\n  # make the service available on this port\n  - port: 22\n    targetPort: 22\n    protocol: TCP\n    name: ssh\n  - port: 80\n    targetPort: 80\n    protocol: TCP\n    name: http\n  selector:\n    # apply this service to the pod with the label app: mysql\n    app: gitlab-ce\n  type: LoadBalancer\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we create on project with one playbook named : query_tenant.yml<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"692\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-26-1024x692.png\" alt=\"\" class=\"wp-image-570\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-26-1024x692.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-26-300x203.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-26-768x519.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-26-1536x1037.png 1536w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-26.png 1978w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The playbook  : query_tenant.yml.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"460\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-27-1024x460.png\" alt=\"\" class=\"wp-image-571\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-27-1024x460.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-27-300x135.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-27-768x345.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-27-1536x690.png 1536w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-27-2048x920.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This is a very basic playbook with three tasks:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The first task is just to verify and understand the parameter push by AWX<\/li><li>The second send a query to get the tenant list in the ACI fabric<\/li><li>The latest is to display the result.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This playbook can be write by a developer and push on Gitlab when it works. Then this playbook will be used in AWX.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The inventory file is used by the developer. Then the credential and inventory will be configured in AWX. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ ansible-playbook -i inventory query_tenant.yml\nPLAY [Play Query] ****\nTASK [Gathering Facts] *\nok: [10.202.0.1]\nTASK [debug - Display Credential used by AWX] ****\nok: [10.202.0.1] =&gt; {\n\"msg\": \"10.202.0.1 - admin - cisco1234\"\n}\nTASK [Query tenant] **\nok: [10.202.0.1]\nTASK [Display Tenant]\nok: [10.202.0.1] =&gt; (item={u'fvTenant': {u'attributes': {u'dn': u'uni\/tn-infra', u'status': u'', u'ownerKey': u'', u'uid': u'0', u'descr': u'', u'extMngdBy': u'', u'annotation': u'', u'lcOwn': u'local', u'monPolDn': u'uni\/tn-common\/monepg-default', u'modTs': u'2019-11-13T18:44:22.536+00:00', u'ownerTag': u'', u'childAction': u'', u'nameAlias': u'', u'name': u'infra'}}}) =&gt; {\n\"msg\": \"Tenant Name: infra\"\n}\nok: [10.202.0.1] =&gt; (item={u'fvTenant': {u'attributes': {u'dn': u'uni\/tn-mgmt', u'status': u'', u'ownerKey': u'', u'uid': u'0', u'descr': u'test', u'extMngdBy': u'', u'annotation': u'', u'lcOwn': u'local', u'monPolDn': u'uni\/tn-common\/monepg-default', u'modTs': u'2020-07-09T16:15:03.963+00:00', u'ownerTag': u'', u'childAction': u'', u'nameAlias': u'', u'name': u'mgmt'}}}) =&gt; {\n\"msg\": \"Tenant Name: mgmt\"\n}\nok: [10.202.0.1] =&gt; (item={u'fvTenant': {u'attributes': {u'dn': u'uni\/tn-common', u'status': u'', u'ownerKey': u'', u'uid': u'0', u'descr': u'', u'extMngdBy': u'msc', u'annotation': u'orchestrator:msc', u'lcOwn': u'local', u'monPolDn': u'uni\/tn-common\/monepg-default', u'modTs': u'2019-11-13T19:45:10.901+00:00', u'ownerTag': u'', u'childAction': u'', u'nameAlias': u'', u'name': u'common'}}}) =&gt; {\n\"msg\": \"Tenant Name: common\"\n}\n[..]\nPLAY RECAP ***\n10.202.0.1 : ok=4 changed=0 unreachable=0 failed=0<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Configure AWX<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Login to AWX<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, it&#8217;s admin \/ password<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"758\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-28-1024x758.png\" alt=\"\" class=\"wp-image-572\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-28-1024x758.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-28-300x222.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-28-768x568.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-28.png 1454w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Create a credential<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here we will create a new credential. With Cisco ACI, we will use the credential type: Machine. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will be able to use it with the following parameter in the playbook:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ansible_username\nansible_password<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"385\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-29-1024x385.png\" alt=\"\" class=\"wp-image-573\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-29-1024x385.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-29-300x113.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-29-768x289.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-29-1536x578.png 1536w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-29-2048x771.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Create a project<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now we create a project. The project will point to a Gitlab repository. We have also selected the option : &#8220;Update Revision on launch&#8221;. This option permits to synchronize Gitlab and get the last version.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"507\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-30-1024x507.png\" alt=\"\" class=\"wp-image-574\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-30-1024x507.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-30-300x148.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-30-768x380.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-30-1536x760.png 1536w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-30-2048x1014.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Create an inventory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In this step we will create an inventory, which contains a Group: APIC with one host : 10.202.0.1 (the ACI controller)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"476\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-31-1024x476.png\" alt=\"\" class=\"wp-image-575\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-31-1024x476.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-31-300x139.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-31-768x357.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-31-1536x714.png 1536w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-31-2048x952.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"332\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-32-1024x332.png\" alt=\"\" class=\"wp-image-576\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-32-1024x332.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-32-300x97.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-32-768x249.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-32-1536x497.png 1536w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-32-2048x663.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"340\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-33-1024x340.png\" alt=\"\" class=\"wp-image-577\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-33-1024x340.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-33-300x100.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-33-768x255.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-33-1536x509.png 1536w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-33-2048x679.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Create a job<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now we need to create one job to play the playbook in GitLab with the inventory and credential in AWX.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You need to enter :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A name<\/li><li>Job type : Run<\/li><li>Inventory, where you select the previous inventory<\/li><li>Project: Just a name<\/li><li>Playbook, where you select the playbook from Git. If you see nothing, the playbook is probably not good.<\/li><li>Credentials, where you select your credential<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"565\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-34-1024x565.png\" alt=\"\" class=\"wp-image-578\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-34-1024x565.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-34-300x165.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-34-768x424.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-34-1536x847.png 1536w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-34-2048x1130.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If everything is good, you can save your Template and launch it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Play template<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After click on the launch button, you will see the following window.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"587\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-35-1024x587.png\" alt=\"\" class=\"wp-image-579\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/image-35-1024x587.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-35-300x172.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-35-768x440.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-35-1536x880.png 1536w, https:\/\/zed-network.fr\/wp-content\/uploads\/image-35-2048x1173.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Install AWX AWX is a GUI tool for Ansible. In this article we will deploy AWX on a Kubernetes cluster. We also have GitLab-CE to store playbooks and manage the version. The first step is to clone AWX: git clone https:\/\/github.com\/ansible\/awx.git Then you need to complete the inventory file. AWX will be deployed with Ansible. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"footnotes":""},"categories":[24,30,28,27],"tags":[],"class_list":["post-568","post","type-post","status-publish","format-standard","hentry","category-aci","category-aci-automation","category-ansible","category-automation"],"_links":{"self":[{"href":"https:\/\/zed-network.fr\/index.php?rest_route=\/wp\/v2\/posts\/568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zed-network.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zed-network.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zed-network.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zed-network.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=568"}],"version-history":[{"count":2,"href":"https:\/\/zed-network.fr\/index.php?rest_route=\/wp\/v2\/posts\/568\/revisions"}],"predecessor-version":[{"id":581,"href":"https:\/\/zed-network.fr\/index.php?rest_route=\/wp\/v2\/posts\/568\/revisions\/581"}],"wp:attachment":[{"href":"https:\/\/zed-network.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zed-network.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zed-network.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}