On Saturday, 18 August 2018 02.42.01 CEST nbctcp wrote:
> [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
---
ansible_network_os=ios
ansible_become=yes
ansible_become_method=enable
ansible_user=cisco
ansible_password=cisco
ansible_become_pass=cisco
--
Kai Stian Olstad
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/2386519.U7Pi4bvNr5%40x1.
For more options, visit https://groups.google.com/d/optout.