cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
607
Views
0
Helpful
6
Replies

Ansible complexity

I have been trying to do basic things with ansible this week and really have struggled to find good resources and documentation that can help in moments of being stuck. I feel this is why most people I talk to have moved from ansible to python. Ansible seems to be a complex python front end. Seems things I use to use are depreciated or not used or have changed. From what I can understand the ios_command thing is not a thing anymore and you are suppose to use cisco.ios.ios_command

 

I have also been trying to configure interfaces at a basic level, like create a loopback and give it an IP address. Error after error and no real way to know what is what and what the issue really is. I am using a hosts_var file to define all the attributes for a host and then trying to slide them into a playbook. 

 

---

- name: configure interface loopback 0
  ios_l3_interfaces:
    config:
      - name: "{{ item.ios_if }}"
        description: "{{ item.desc }}"
        enabled: "{{ item.enabled }}"
        address: "{{ item.ipv4 }}"

I know the assembly of the code is probably wrong but it doesnt even like ios_l3_interfaces.

 

ERROR! 'ios_l3_interfaces' is not a valid attribute for a Play

The error appears to be in '/Users/swilliams/GitHubRepos/Ansible-Master-Directory/Ansible_6_Router_Lab/config_commands/create_loopback.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: configure interface loopback 0

I am really wondering if I should be ditching ansible and moving to something more solid like python. 

6 REPLIES 6
Claudia de Luna
Enthusiast

Hi @stevenjwilliams0728,

 

Can you confirm the version of Ansible you are using?  I believe you are on 10 and 10 just did a major re-structuring and is also relatively new so I suspect there is not much out there.  I know thats on my to do list (update some of the repost I use for training to 2.10) but have not gotten a chance to spend time on that yet.

 

I think if you try Ansible 2.9 you will find lots of good examples. 

 

As to moving to Python...If you are already comfortable with Python and if you can see yourself having to do complex things or actions for which no modules currently exist then that might be something to seriously consider.   Have you looked at Nornir?
There are some good Nornir Intro repositories on DevNet Code exchange if you want to take a peek.

Once you get the hang of Ansible and if there are modules its a very nice framework.  Just don't go to 2.10 just yet!
Nornir repos on DevNet Code Exchange

 

swilliams@Stevens-MacBook-Pro ~ % ansible --version

ansible 2.9.13

  config file = /Users/swilliams/ansible.cfg

  configured module search path = ['/Users/swilliams/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

  ansible python module location = /usr/local/Cellar/ansible/2.9.13/libexec/lib/python3.8/site-packages/ansible

  executable location = /usr/local/bin/ansible

  python version = 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)]

swilliams@Stevens-MacBook-Pro ~ %

See if this works for you:

Make sure all the options you are providing are supported.

 

root@e340c7ef8161:/ansible_local/cisco_ios# cat l3.yml
---
###############################################################################
# This playbook utilizes the ios_l3_command ansible module to execute interface
# configuration commands
#
# EXECUTION:
# ansible-playbook -i hosts l3.yml
###############################################################################

- name: Interface Management
  hosts: cisco_xe

  gather_facts: False
  ignore_errors: yes

  tasks:
    - name: Interface Management
      ios_l3_interfaces:
        config:
          - name: GigabitEthernet3
            ipv4:
              - address: 192.168.99.1/24
        state: merged

      register: output

    - debug: var=output


root@e340c7ef8161:/ansible_local/cisco_ios#
Seb Rupik
VIP Advisor

Hi there,

Try the following:

 

---

- name: configure interface loopback 0
  ios_l3_interfaces:
    config:
      - name: "{{ item.ios_if }}"
        ipv4:
          - address: "{{ item.ipv4 }}"


...

Note, that you need to specify the full path to the module when referenced in the play. Also 'description' and 'enabled' are not supported parameters in the module.

 

If in doubt read the docs for the version you are using. the examples at the bottom should cover all use cases.

https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_l3_interfaces_module.html

 

cheers,

Seb.

Nope still not getting any headway here. 

 

ERROR! 'ios_l3_interfaces' is not a valid attribute for a Play

The error appears to be in '/Users/swilliams/GitHubRepos/Ansible-Master-Directory/Ansible_6_Router_Lab/config_commands/create_loopback.yml': line 4, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: configure interface loopback 0
  ^ here

I have no idea what is wrong. What output can I/you look at to make sure my environmentals are set up correctly here?

Hi...if you want to PM me your playbook or the link to your repo I'm happy to take a peek. 

Content for Community-Ad

This widget could not be displayed.