Hi,
I have working playbook to cisco on eve-ng.
It will give error only when I want to run “show run”.
Other commands like “show version” “show clock” all ok
Please help
tq
Hi,
I have working playbook to cisco on eve-ng.
It will give error only when I want to run “show run”.
Other commands like “show version” “show clock” all ok
Please help
tq
show run need enable if I remember correctly.
How to use enable with network_cli is documented here
https://docs.ansible.com/ansible/2.6/network/user_guide/platform_ios.html
It will work if I put username and password directly in hosts, but not if separate file.
I want separate file so that I can do vault on it
$ cat ansible.cfg
[defaults]
inventory = hosts
host_key_checking = False
pipelining = True
retry_files_enabled = False
display_skipped_hosts = True
log_path = /tmp/ansible.log
[persistent_connection]
command_timeout=100
connect_timeout=100
connect_retry_timeout=100
$ cat hosts
[cisco]
cisco1 ansible_host=10.0.10.121
[cisco:vars]
ansible_network_os=ios
ansible_become=yes
ansible_become_method=enable
ansible_user=cisco
ansible_password=cisco
ansible_become_pass=cisco
[cisco]
cisco1 ansible_host=10.0.10.121[cisco:vars]
ansible_network_os=ios
ansible_become=yes
ansible_become_method=enable
ansible_user=cisco
ansible_password=cisco
ansible_become_pass=cisco# cat playbooks/showrun.yml
---
- name: Run multiple commands
connection: network_cli
hosts: cisco1
gather_facts: true
tasks:
- name: run multiple commands
ios_command:
commands:
register: output
- name: copy output to file
copy: content="{{ output.stdout[0] }}" dest=./output/{{
inventory_hostname }}.txt
- debug: var=output.stdout_lines
...BUT NOT
# cat hosts
[cisco]
cisco1 ansible_host=10.0.10.121# cat playbooks/showrun.yml
---
- name: show run
connection: network_cli
hosts: cisco1
gather_facts: no
tasks:
- name: GET CREDENTIALS
include_vars: ../group_vars/secretsios.yml
You shouldn't do this, group_vars is special in Ansible and automatically load variables from this directory.
So if you have a group called "mygroup" it will load the file group_vars/mygroup.yml for all host in that group.
In your case this is for the group called "secretsios".
If this is only manually loaded variables you should choose another name since group_vars has special meaning.
- name: DEFINE CONNECTION
set_fact:
connection:
authorize: yes
host: "{{ inventory_hostname }}"
username: "{{ creds['username'] }}"
password: "{{ creds['password'] }}"
auth_pass: "{{ creds['auth_pass'] }}"
You aren't using the variable anywhere in your playbook so this have no effect, and you shouldn't use variable name that is the same as Ansible directive.
Instead, you should create a file group_vars/cisco.yml since your host is in the cisco group.
The content should be the same as your vars in the inventory of your first example.
group_vars/cisco.yml