Hey EE1, 

As you rightly pointed out --limit works and -i don't, as you reported you 
are getting desired output for `ansible-inventory --host csr1` which 
indicates the inventory is already being picked up correctly.
To *limit the hosts you target on a particular run *we use *--limit *flag, -i 
on the other hand points to an inventory as a whole, not particular hosts. 
you might get more clarity here 
<https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html>.

Regards,
Sagar Paul
E - [email protected]
G - KB-perByte

On Wednesday, March 16, 2022 at 3:20:35 AM UTC+5:30 EE1 wrote:

> Additional information after more testing.  All seems to work if I use 
> --limit instead of -i.
>
> I.e.:
>
> This works:
> ansible-playbook -k first_playbook_ext_ios2.yml --limit csr1
>
> This does not work:
> ansible-playbook -i csr1, first_playbook_ext_ios2.yml -k
>
> Is this expected behavior?  Any pointers or doc links on what I'm missing 
> in terms of differences between the two options above?
>
> Thank you!
>
> On Tuesday, March 15, 2022 at 4:11:21 PM UTC-4 EE1 wrote:
>
>> Hi All,
>>
>> I seem to be having an issue defining a variables in my 
>> /etc/ansible/hosts.  When I run a playbook against a host in my inventory, 
>> it seems the variable are not read based on the error messages.  For 
>> example, here it seems to not see the network os variable:
>>
>> ansible-playbook -i csr1, first_playbook_ext_ios2.yml
>>
>> PLAY [Network Getting Started First Playbook - Change Hostname] 
>> ****************************************************************************************************************
>>
>> TASK [Get old config for ios devices] 
>> ******************************************************************************************************************************************
>> fatal: [csr1]: FAILED! => {"msg": "Unable to automatically determine host 
>> network os. Please manually configure ansible_network_os value for this 
>> host"}
>>
>> PLAY RECAP 
>> *********************************************************************************************************************************************************************
>> csr1                       : ok=0    changed=0    unreachable=0   
>>  failed=1    skipped=0    rescued=0    ignored=0
>>
>> Even though the variable is defined and shows up in ansible-inventory:
>>
>>  ansible-inventory --host csr1
>> {
>>     "ansible_become": true,
>>     "ansible_become_method": "enable",
>>     "ansible_become_password": "cisco",
>>     "ansible_host": "192.168.1.73",
>>     "ansible_network_os": "ios",
>>     "ansible_user": "admin"
>> }
>>
>> Here is the hosts file:
>>
>> cat /etc/ansible/hosts
>> ---
>> nxos:
>>   hosts:
>>     nxos1:
>>       ansible_host: 192.168.1.71
>>     nxos2:
>>       ansible_host: 192.168.1.72
>>   vars:
>>     ansible_network_os: nxos
>>
>> ios:
>>   hosts:
>>     csr1:
>>       ansible_host: 192.168.1.73
>>   vars:
>>     ansible_network_os: ios
>>     ansible_become: yes
>>     ansible_become_method: enable
>>     ansible_become_password: cisco
>>
>> network:
>>   children:
>>     ios:
>>     nxos:
>>   vars:
>>     ansible_user: admin
>>
>>
>> If I set the os variable manually at the command line, then it seems to 
>> fail on the name alias part:
>>
>> ansible-playbook -i csr1, first_playbook_ext_ios2.yml -e 
>> ansible_network_os=ios
>>
>> PLAY [Network Getting Started First Playbook - Change Hostname] 
>> ****************************************************************************************************************
>>
>> TASK [Get old config for ios devices] 
>> ******************************************************************************************************************************************
>> fatal: [csr1]: FAILED! => {"changed": false, "msg": "[Errno -3] Temporary 
>> failure in name resolution"}
>>
>> PLAY RECAP 
>> *********************************************************************************************************************************************************************
>> csr1                       : ok=0    changed=0    unreachable=0   
>>  failed=1    skipped=0    rescued=0    ignored=0
>>
>> Is something obvious wrong with my inventory file?  Anything else this 
>> newbie is overlooking?
>>
>> Thanks in advance.
>>  
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4db80b6f-7460-41ce-b777-2297b7058196n%40googlegroups.com.

Reply via email to