cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2039
Views
10
Helpful
1
Replies

Ansible Cisco ios questions

Difan Zhao
Level 5
Level 5

Hi gurus,

I recently started to learn ansible for network automation. I run into a few questions that I can't find answers with my google skills...

1. How to list all the installed modules? "ansible-doc -l" lists everything available ansible offers I think. Is there a way to list only the installed ones on the localhost? I found "ansible-galaxy collection list" to see the collections but not the modules..

2. In the module cisco.ios.ios_facts, what is the difference between "gather_network_resources" and "gather_subset"? 

3. In the playbook at the top, what does "gather_facts" do? Does it affect the output of the iso_facts module?

4. I see in the examples, they use short names for the modules and variables. For example, they use network_cli instead of ansible.netcommon.network_cli, or ios_facts rather than cisco.ios.ios_facts. What's the rule for that? 

5. How do I know what variables the module uses? How do I know their names? For example, if I use the ios_facts module, what are the returned values, and what variables are used to store them? I found on the Internet something like hostvars, ansible_facts, ...etc but I want to know where you would go to get such a list. I tried "ansible-doc -s cisco.ios.ios_facts" for instructions on the module but it is not there.

6. I tried to set "ansible_network_os: cisco.ios.ios" in the playbook but I got this error. I have no problem setting in the hosts inventory file (with ansible_network_os = cisco.ios.ios). Why is that? 

 

 

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

Sorry about the long list but I am ready to give points for any helpful answers to any of my questions!!

Thanks!

Difan

 

1 Reply 1

Sergiu.Daniluk
VIP Alumni
VIP Alumni

Hi @Difan Zhao

First of all, welcome to network automation!

Allow me to try and answer to your questions:


1. How to list all the installed modules?

You can use ansible-doc --list_files command. It will list all modules installed plus the location of the module itself. You can also use ansible-doc -l to see description of each module.

Myself, I sometimes like to go directly to the modules directory and browse through them to see exactly what are they doing.

That's in /venv/lib/python3.8/site-packages/ansible_collections 

Normally, all the "installed" modules in the version of ansible you are running, should also be visible here: https://docs.ansible.com/ansible/latest/collections/index_module.html  Of course, you need to select the version you have in the top left corner.


2. What is the difference between "gather_network_resources" and "gather_subset"?

In the docs you have a description for every returned parameter: https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_facts_module.html#parameters  If you want to see it in more detail, exactly what each parameter contains (without running the module) you can go and read the python file, located at /venv/lib/python3.8/site-packages/ansible_collections/cisco/ios/plugins/modules/ios_facts.py. Some snip from the python file:

ansible_net_gather_subset:
description: The list of fact subsets collected from the device
returned: always
type: list

ansible_net_gather_network_resources:
description: The list of fact for network resource subsets collected from the device
returned: when the resource is configured
type: list


3. In the playbook at the top, what does "gather_facts" do?
I suppose here you refer to the builtin gather_facts module. This module is automatically called by playbooks to gather useful variables about remote hosts that can be used in playbooks. You can turn off fact gathering at the play level to improve scalability. Disabling facts may particularly improve performance with very large numbers of systems. Disable it like this:

- hosts: whatever
gather_facts: no


4. What's the rule for using short names?
In most cases, you can use the short module name even without specifying the collection. I think the rule is simple: if the name is unique, you can use short name. If not, use the full name to avoid name collision.


5. How do I know what variables the module uses?
Everything is described in the module description. The list of all collections can be found here: https://docs.ansible.com/ansible/latest/collections/index.html  Clicking on one collection will list all available modules in the collection. Clicking on the module you will see all details related to the module (variables, example of how to use and returned variables)


6. Why I receive "not a valid attribute" error?
Most likely you have a problem with the indentation. Check again the playbook and how you wrote and be very careful about how you indent everything.


Hope it helps.


Stay safe,

Sergiu

 

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: