cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5975
Views
0
Helpful
8
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. 

8 Replies 8

Claudia de Luna
Spotlight
Spotlight

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 Alumni
VIP Alumni

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. 

i have EXACTLY that problem and don´t get why...feeling a bit dumb, because my 

 

$ansible <WHATEVERGROUPITRY> -m ping

 

works perfectly fine, my ansible version is above 2.9, i installed collctions successfully via

 

$ansible-galaxy collection install community.network cisco.nxos cisco.ios cisco.iosxr

 

So, basically i thought i should be fine to run a playbook...and i am stuck already here.

Did you have a solution to that problem by now?

 

Thanks in advance,

Andreas

 

Not sure if this issue with the "

- name: configure interface loopback 0
  ^ here

" errors has been resolved on this post yet.....but I will say I had a similar issue just this past day where I kept getting the same error even though I knew syntax was correct.

The issue ended up being conflicting module versions/path between Ansible installed by CentOS Yum package manager and Python 2.7 Pip installed version. One was running the newer Core Ansible where the module for l3 is now "ios_l3_interfaces" plural instead of classic "..._interface" in the older versions.

 

Long story but a somewhat easy and smooth fix was to remove the Yum installed Ansible 2.9.....install Python3 and associated newest Ansible Core (2.11.2) with SUDO privs ...... created a clean (no site globals) virtual-environment in Python3 as the user, pip installed Ansible Core in the venv.......and after a few syntax changes in my play, the classic and new module for "ios_l3_interface(s)" works great in the venv.

 

Hope that helps

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: