Hi There, I am new to Ansible so just learning at the moment and have a question regarding variables and how to access them under specific scenarios.
A bit of background, I’ve setup a couple of inventory files and splitting them out for various different functions and I have a couple of basic playbooks, mostly for discovering information about my network. This all works great.
What I’m struggling to understand, if I want to use the ping module from the command line, how can i get ansible to use my stored variable for username and password. When i do this using a playbook I have an entry in the YAML file pointing at the var_files, like shown below:
- name: Gather Facts from Cisco IOS Devices
hosts: corp_edge_cisco
gather_facts: true
vars_files: ../groupvars/default.yaml
tasks:
- name: Gather facts
But when I run the following command:
ansible corp_edge_cisco -i ansible/inventory/corp_edge_network.ansible.yaml -m ping
This does not have a reference to where the variables are stored so throws the following error:
cisco | FAILED! => {
"msg": "The field 'remote_user' has an invalid value, which includes an undefined variable. The error was: 'netadmin_username' is undefined. 'netadmin_username' is undefined"
}
I’m aware I could create a playbook which defines a task to ping and passes the varible file, but I’m wondering if the structure I have in place is wrong and maybe the inventory file should be linking directly to the variable files?