{"id":375,"date":"2019-05-24T17:12:43","date_gmt":"2019-05-24T16:12:43","guid":{"rendered":"https:\/\/zed-network.fr\/?p=375"},"modified":"2020-08-24T19:26:40","modified_gmt":"2020-08-24T18:26:40","slug":"programming-cisco-with-ansible","status":"publish","type":"post","link":"https:\/\/zed-network.fr\/?p=375","title":{"rendered":"How to program Cisco ACI with Ansible and Docker"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Ansible guide :  <a href=\"https:\/\/docs.ansible.com\/ansible\/devel\/scenario_guides\/guide_aci.html\">https:\/\/docs.ansible.com\/ansible\/devel\/scenario_guides\/guide_aci.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I create a docker container with ansible, python and the demo from github.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git clone https:\/\/github.com\/CiscoDevNet\/aci-learning-labs-code-samples \ncd aci-learning-labs-code-samples <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">docker image with ansible and python: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker pull zednetwork\/aci-ansible2-4<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">New version with ansible 2.8.2 using debian 10.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">docker pull zednetwork\/aci-ansible.2-8-2<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Docker Compose example:<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">version: \"3\" \nservices:\n  ansible:\n    image: zednetwork\/aci-ansible2-4\n    tty: true\n    stdin_open: true<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Start the container and connect to it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>docker-compose up -d <\/strong>\nCreating network \"aci-ansible_default\" with the default driver\n\nPulling ansible (zednetwork\/aci-ansible2-4:)\u2026\n\nlatest: Pulling from zednetwork\/aci-ansible2-4\n\n22dbe790f715: Downloading [&gt;                                                  ]  465.6kB\/45.34 MBf88405a685: Pulling fs layer\n\n22dbe790f715: Downloading [=&gt;                                                 &lt;..&gt;\n22dbe790f715: Pull complete\n3bf88405a685: Pull complete\nCreating aci-ansible_ansible_1 \u2026 done<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Check container<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"># docker images\n REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE\n zednetwork\/aci-ansible2-4   latest              ff17ed37f691        34 minutes ago      659MB\n\n# docker ps\n CONTAINER ID        IMAGE                       COMMAND             CREATED              STATUS              PORTS               NAMES\n 53993071ffa9        zednetwork\/aci-ansible2-4   \"bash\"              About a minute ago   Up About a minute                       aci-ansible_ansible_1<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Connect to the container. Use the Container ID above.<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"># docker exec -it 53993071ffa9 \/bin\/bash\nroot@53993071ffa9:\/#<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This container already contains an example from devnet.cisco.com ( <a href=\"https:\/\/developer.cisco.com\/docs\/aci\/#ansible\">https:\/\/developer.cisco.com\/docs\/aci\/#ansible<\/a>). This example uses a public ACI Fabric.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can use the first playbook to create a tenant on the ACI Fabric. The fabric credential is on the inventory file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@53993071ffa9:~\/aci_ansible_learning_labs_code_samples\/intro_module# cat inventory\n [apic:vars]\n username=admin\n password=ciscopsdt\n ansible_python_interpreter=\"\/usr\/bin\/env python\"\n [apic]\n sandboxapicdc.cisco.com<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can connect directly to the fabric and verify if your tenant is present.  <a href=\"https:\/\/sandboxapicdc.cisco.com\/\">https:\/\/sandboxapicdc.cisco.com\/<\/a> <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@53993071ffa9:~\/aci_ansible_learning_labs_code_samples\/intro_module# ansible-playbook -i inventory 01_aci_tenant_pb.yml\n What would you like to name your Tenant?: MyFirstTenant-tn\n PLAY [ENSURE APPLICATION CONFIGURATION EXISTS] \n TASK [ENSURE APPLICATIONS TENANT EXISTS] \n changed: [sandboxapicdc.cisco.com]\n PLAY RECAP \n sandboxapicdc.cisco.com    : ok=1    changed=1    unreachable=0    failed=0<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go to <strong>ACI &gt; Tenants <\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img fetchpriority=\"high\" decoding=\"async\" width=\"800\" height=\"398\" class=\"wp-image-376\" style=\"width: 800px;\" src=\"https:\/\/zed-network.fr\/wp-content\/uploads\/Newtenant.png\" alt=\"\" srcset=\"https:\/\/zed-network.fr\/wp-content\/uploads\/Newtenant.png 1085w, https:\/\/zed-network.fr\/wp-content\/uploads\/Newtenant-300x149.png 300w, https:\/\/zed-network.fr\/wp-content\/uploads\/Newtenant-768x382.png 768w, https:\/\/zed-network.fr\/wp-content\/uploads\/Newtenant-1024x510.png 1024w, https:\/\/zed-network.fr\/wp-content\/uploads\/Newtenant-500x249.png 500w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can delete your tenant with another playbook<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@53993071ffa9:~\/aci_ansible_learning_labs_code_samples\/intro_module# ansible-playbook -i inventory 01-1_aci_tenant_pb.yml\n What would you like to name your Tenant?: MyFirstTenant-tn\n PLAY [ENSURE APPLICATION CONFIGURATION EXISTS] \n TASK [ENSURE APPLICATIONS TENANT EXISTS] \n changed: [sandboxapicdc.cisco.com]\n PLAY RECAP \n sandboxapicdc.cisco.com    : ok=1    changed=1    unreachable=0    failed=0<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Other example to list all tenants:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># cat listTenants.yml\n---\n- name: ENSURE APPLICATION CONFIGURATION EXISTS\n  hosts: apic\n  connection: local\n  gather_facts: False\n  \n  tasks:\n\n    - name: List all tenants\n        aci_tenant:\n        host: \"{{ ansible_host }}\"\n        username: \"{{ username }}\"\n        password: \"{{ password }}\"\n        state: \"query\"\n      validate_certs: False \n\n# ansible-playbook -i inventory listTenants.yml -vvv\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ansible guide : https:\/\/docs.ansible.com\/ansible\/devel\/scenario_guides\/guide_aci.html I create a docker container with ansible, python and the demo from github. git clone https:\/\/github.com\/CiscoDevNet\/aci-learning-labs-code-samples cd aci-learning-labs-code-samples docker image with ansible and python: docker pull zednetwork\/aci-ansible2-4 New version with ansible 2.8.2 using debian 10. docker pull zednetwork\/aci-ansible.2-8-2 Docker Compose example: version: &#8220;3&#8221; services: ansible: image: zednetwork\/aci-ansible2-4 tty: true stdin_open: true [&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-375","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\/375","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=375"}],"version-history":[{"count":6,"href":"https:\/\/zed-network.fr\/index.php?rest_route=\/wp\/v2\/posts\/375\/revisions"}],"predecessor-version":[{"id":547,"href":"https:\/\/zed-network.fr\/index.php?rest_route=\/wp\/v2\/posts\/375\/revisions\/547"}],"wp:attachment":[{"href":"https:\/\/zed-network.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zed-network.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zed-network.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}