cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2372
Views
0
Helpful
2
Replies

Ansible + Cobra SDK + Jason Edelman's aci-ansible repo

black
Level 1
Level 1

Hi,

Hoping this is something easily solved. I'm new to ansible, ACI, and the Cobra SDK. I'm seeing this error when I try to run an ansible playbook that uses Jason Edelman's aci-ansible library. It's not finding the Cobra SDK, even though it appears to be installed. The specific error when I run the playbook is:

fatal: [10.10.10.10]: FAILED! => {"changed": false, "error": "No module named cobra.mit.access", "failed": true, "msg": "Ensure you have the ACI Cobra SDK installed"}

And here are the steps I've taken to install the ansible library and SDK, most of which comes directly from the instructions posted on the ACI controller.

git clone https://github.com/jedelman8/aci-ansible.git ~/ansible/aci-ansible
mkdir ~/cobra_sdk_2.2_1o
cd ~/cobra_sdk_2.2_1o
sudo easy_install virtualenv
cd ~
virtualenv cobra_sdk_2.2_1o
source cobra_sdk_2.2_1o/bin/activate
cd ~/cobra_sdk_2.2_1o
easy_install -Z acicobra-2.2_1o-py2.7.egg
easy_install -Z acimodel-2.2_1o-py2.7.egg

Once this is done, it appears to be there and working.

(cobra_sdk_2.2_1o) sdfsd@sfsdf12:~/cobra_sdk_2.2_1o$ pip freeze
acicobra===2.2-1o
acimodel===2.2-1o
appdirs==1.4.3
packaging==16.8
pyparsing==2.2.0
requests==2.13.0
six==1.10.0

I'm also able to import from python.

(cobra_sdk_2.2_1o) sdfd@sdfd12:~/cobra_sdk_2.2_1o$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from cobra.mit.access import MoDirectory
>>>

And here is my playbook:

---
- hosts: "{{ host_list }}"
gather_facts: no
connection: local

tasks:

- name: define user
set_fact:
user: bart

- name: define pass
set_fact:
pass: simpson

- name: build a test bridge domain
aci_bridge_domain: name=1212_DELETEME context=aaa tenant=b state=present host={{ inventory_hostname }} username={{ user }} password={{ pass }}

- name: remove a test bridge domain
aci_bridge_domain: name=1212_DELETEME context=aaa tenant=b state=absent host={{ inventory_hostname }} username={{ user }} password={{ pass }}

But whenever I run it, it fails with the following error (same as listed above). Any ideas?

fatal: [10.0.49.34]: FAILED! => {"changed": false, "error": "No module named cobra.mit.access", "failed": true, "msg": "Ensure you have the ACI Cobra SDK installed"}

Thanks in advance for any insight!

2 Replies 2

Not applicable

Hello,


Have you tried using, ansible_python_interpreter, to force Ansible to use Python that is within your virtualenv? I believe that by default Ansible will try to use /usr/bin/python

Here is an example that I use on my system

ansible-playbook -i hosts aci_frmw_download.yml  -e "ansible_python_interpreter=../bin/python"
You can also add the, ansible_python_interpreter into your inventory file as well.
Steve

Jimena Saez
Community Manager
Community Manager

Hi @black 

We opened a forum in French with an ACI expert & VIP of the community Francesco Molino who answered your question. Please validate his reply as "accepted solution" here or visit our forum !

 

Hi @black 

 

I see your playbook refers to a module called aci_bridge_domain which doesn't exist in the code you are using.

The correct module would be: aci_bd.

Also, you can share the contents of your ansible.cfg file or your host file which should refer the python program to use:

 

ansible_python_interpreter=/usr/bin/python3

 

Now this library is 4 years old and I would advise you to use the ansible cisco.aci collection (https://galaxy.ansible.com/cisco/aci)

You will need to use aci_bd and aci_bd_subnet. On the web page of the cisco.aci collection on ansible, you will find the different parameters to use as well as examples.

For info, here is an example below

    - name: Create Bridge Domain
      aci_bd:
        host: '{{ ansible_host }}'
        username: '{{ username }}'
        private_key: '{{ private_key }}'
        certificate_name: '{{ certificate_name }}'
        validate_certs: no
        tenant: '{{ item.TENANT }}'
        bd: '{{ item.BD }}'
        vrf: '{{ item.VRF_FULL }}'
        enable_multicast: 'yes'
        enable_routing: 'yes'
        l2_unknown_unicast: 'proxy'
        l3_unknown_multicast: 'flood'
        multi_dest: 'bd-flood'
        arp_flooding: 'yes'
        state: present
      tags: l3
      loop: '{{ l3_list }}'

    - name: Create Bridge Domain Subnet
      aci_bd_subnet:
        host: "{{ ansible_host }}"
        username: '{{ username }}'
        private_key: '{{ private_key }}'
        certificate_name: '{{ certificate_name }}'
        validate_certs: no
        tenant: '{{ item.TENANT }}'
        bd: '{{ item.BD }}'
        gateway: "{{ item.ANYCAST_GATEWAY }}"
        mask: "{{ (item.BD_SUBNET).split('/')[1] | int }}"
        scope: public
        state: present
      tags: l3
      loop: '{{ l3 }}'

In my example, there is a loop which calls a variable l3 because I am using an excel file with several subnets to create but if you want a single bridge-domain, you can adapt it as follows:

 

    - name: Create Bridge Domain
      aci_bd:
        host: '{{ ansible_host }}'
        username: '{{ username }}'
        private_key: '{{ private_key }}'
        certificate_name: '{{ certificate_name }}'
        validate_certs: no
        tenant: 'TEST_TENANT'
        bd: 'TEST_BD'
        vrf: 'TEST_VRF'
        enable_multicast: 'yes'
        enable_routing: 'yes'
        l2_unknown_unicast: 'proxy'
        l3_unknown_multicast: 'flood'
        multi_dest: 'bd-flood'
        arp_flooding: 'yes'
        state: present

    - name: Create Bridge Domain Subnet
      aci_bd_subnet:
        host: "{{ ansible_host }}"
        username: '{{ username }}'
        private_key: '{{ private_key }}'
        certificate_name: '{{ certificate_name }}'
        validate_certs: no
        tenant: 'TEST_TENANT'
        bd: 'TEST_BD'
        gateway: "10.10.10.1"
        mask: "24"
        scope: public
        state: present

 

Save 25% on Day-2 Operations Add-On License