Hi Hawkesworth,
I have followed your instruction and it's working so my inventories are now 
working like I wanted. My end goal is to run show_vlan.yml role on the 
requested inventory but im getting syntax problem on my include_role module.
(ansible now fetching the right hosts from the right inventory just like I 
wanted so the inventory problem is behind us)

About the role configuration,
This is my playbook:
- 
  name: Loading Ansible Environment
  hosts: POC_ENV
  connection: local
  vars:
    vlan_id: 999
    vlan_name: TEST_VLAN_TEST
    ansible_ssh_private_key_file: /home/ansible/.ssh/id_rsa
    ansible_ssh_common_args: 
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
    ansible_user: ansible

- 
  name: Playing VLAN Configuration
    include_role:
    name: show_vlan.yml

# Final result = run show_vlan on requested predefined group

This is my show_vlan.yml file that is located on 
/etc/ansible/roles/show_vlan.yml:
- name: Show VLAN
  ios_command:
      commands: show vlan brief
      register: show_vlan

- debug: var=show_vlan.stdout_lines

basically, all it does its the execute the show vlan brief command on the 
switch and register it in show_vlan variable.

As you can see in the error below it is failing on syntax problem:

[image: Ansible add vlans errors.PNG]


What is wrong in my playbook.yml file? and can you please tell me if my 
show_vlan.yml located properly on my directory and if it is configured 
correctly.

Thanks in advance.!




מאת J Hawkesworth:
>
> I suggest doing this:
>
> mkdir /etc/ansible/inventory
> # copy POC_ENV.yml, avaya.yml, nexus.yml to /etc/ansible/inventory
> changing your ansible.cfg so that it looks for inventory in 
>
> /etc/ansible/inventory
>
> IIRC that will load all the inventory files in that directory
>
> I have not tried this using .yaml format inventory file but it works fine 
> using ini format so I suspect it will work ok using .yaml format inventory.
>
> If you run 
> ansible-playbook -vvvvvv a_test_playbook.yml 
>
> the first few lines will show you where it is looking for inventory and 
> what plugins it is using to parse and load your inventory.
>
> Hope this helps,
>
> Jon
>
> On Tuesday, December 31, 2019 at 10:13:25 AM UTC, Yehuda Pinhas wrote:
>>
>> Hi J Hawkesworth,
>> Can you explain exactly in which file do I need to add what code?
>>
>> Considering I have the inventories POC_ENV.yml, avaya.yml, nexus.yml for 
>> example. What file do I need to edit? the ansible.cfg and the inventory 
>> file? can you provide the exact solution?
>>
>> currently my ansible.cfg file directs to /etc/ansible/inventory.yml
>>
>> and my inventory.yml is empty (which is the master inventory as i 
>> understand and from it I am supposed to direct ansible to each one of the 
>> inventories mentioned above such as POC_ENV.yml,etc.)
>>
>>
>>
>>
>>
>>  J Hawkesworth:
>>>
>>> I suggest using a directory that contains the files you need to build up 
>>> your inventory.  You can also use symlinks I think
>>> This is described in the documentation in the section starting 
>>> '*Aggregating 
>>> inventory sources with a directory' *here:
>>>
>>> https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#using-multiple-inventory-sources
>>>
>>> I think this might be a simpler way to achieve what you want rather than 
>>> using add_host and including lots of inventory files directly into your 
>>> playbook.
>>>
>>> It does depend on not having hostnames that clash of course.
>>>
>>> Hope this helps,
>>>
>>> Jon
>>>
>>>>
>>>>

-- 
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/b3a6afcc-75ae-4a79-9850-92bd069647ac%40googlegroups.com.

Reply via email to