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: Playing VLAN Configuration hosts: POC_ENV connection: local vars: ansible_ssh_private_key_file: /home/ansible/.ssh/id_rsa ansible_ssh_common_args: -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ansible_user: ansible vlan_id: 999 vlan_name: TEST_VLAN_TEST tasks: - include_role: name: show_vlan # Final result = run show_vlan on requested predefined group This is the role that is located on /etc/ansible/roles/tasks/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 and supposed to print it to my screen with stdout_lines. As you can see in the error below it is failing for some reason, seems that its failing to find the role show_vlan that I have requested: [image: Ansible add vlans errors.PNG] What am I missing? 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/efed4aa7-01eb-4b0e-be00-5aa3d74090a6%40googlegroups.com.