# Problem choosing proper structure of my ansible playbook/inventory

**URL:** <https://forum.ansible.com/t/problem-choosing-proper-structure-of-my-ansible-playbook-inventory/25750>\
**Category:** Ansible Project\
**Created:** [October 14, 2017, 1:04pm UTC](https://forum.ansible.com/t/problem-choosing-proper-structure-of-my-ansible-playbook-inventory/25750 "2017-10-14T13:04:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fredrik\_T](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/fredrik_t/32/2505_2.png) [@Fredrik\_T](https://forum.ansible.com/u/Fredrik_T)\
**Post date:** [October 14, 2017, 1:04pm UTC](https://forum.ansible.com/t/problem-choosing-proper-structure-of-my-ansible-playbook-inventory/25750/1 "2017-10-14T13:04:51Z")

</div>

Trying to figure out how to the get following solved. Coming from Puppet I have a bit of an adjustment to make.

I’m trying to configure a few comware/arista switches which are only accessible via a certain jump host.

**My inventory look like** :

`  
**[comware]**  
switch1  
switch2

**[arista]**  
switch3

**[switches:children]**  
comware  
arista  
`

First my though was to create a role named “my-switches”  
Create a playbook with the hosts set to “switches” which would loop through the list [switch1, switch2, switch3]  
Since they are only accessable via a certain jump-node I though using the “delegate\_to: jump\_host” for each tasks.

But I also get some pre-tasks I would like to have executed installing required pip packages on the jump\_host.

Could really get this sorted out. Pre-tasks not running on the correct host so then I switched to a different way of doing this.

Created a dict in the group\_vars/all.yml

`switches: user: admin pass: password list: switch1: flavor: comware switch2: flavor: comare switch3: flavor: arista`

And then setting the hosts in the playbook to “jump\_host”. Now the pre-tasks installs correctly and I’m using with\_items to loop switches.list  
But delegate\_to seems to be overrided by the fact that hosts in the playbook is set to “jump\_host”.

The comware module runs ssh against my jump\_host for every loop (with\_items) in roles/my-switches/tasks/main.yml.  
Some how feels incorrect to build up a list of switches to iterate over instead of using the inventory.

Not exactly sure what I’m failing to understand. Tried using the ansible\_host variable in the role but I’m guessing it gets overruled by the hosts: jump\_host defined in the playbook.

Maybe I’m jumping into ansible not doing the proper homework first of passing the primer.

Did my question even make sense?

Also would be nice to be able to figure out which group a switch came from in my first example to get the flavor of it not using extra variables when using groups of groups.

Thanks!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 14, 2017, 2:50pm UTC](https://forum.ansible.com/t/problem-choosing-proper-structure-of-my-ansible-playbook-inventory/25750/2 "2017-10-14T14:50:38Z")

</div>

Have you look at this?  
[https://docs.ansible.com/ansible/latest/faq.html#how-do-i-configure-a-jump-host-to-access-servers-that-i-have-no-direct-access-to](https://docs.ansible.com/ansible/latest/faq.html#how-do-i-configure-a-jump-host-to-access-servers-that-i-have-no-direct-access-to)

---

<div class="post-metadata">

**Author:** ![Fredrik\_T](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/fredrik_t/32/2505_2.png) [@Fredrik\_T](https://forum.ansible.com/u/Fredrik_T)\
**Post date:** [October 14, 2017, 7:18pm UTC](https://forum.ansible.com/t/problem-choosing-proper-structure-of-my-ansible-playbook-inventory/25750/3 "2017-10-14T19:18:50Z")

</div>

Thanks Kai for responding!

Seen that one. Maybe jump\_host was really as missleading name. It’s really the name of the host I want having execute the commands. Thinking this is the use of delegate\_to.  
/Fredrik

---

<div class="post-metadata">

**Author:** ![Fredrik\_T](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/fredrik_t/32/2505_2.png) [@Fredrik\_T](https://forum.ansible.com/u/Fredrik_T)\
**Post date:** [October 14, 2017, 7:53pm UTC](https://forum.ansible.com/t/problem-choosing-proper-structure-of-my-ansible-playbook-inventory/25750/4 "2017-10-14T19:53:25Z")

</div>

Seems to be more related to variable precedence

`failed: [cmu.lab.net] (item=v300) => { "changed": false, "failed": true, "invocation": { "module_args": { "descr": "Mitt vlan 300", "hostname": "cmu.lab.net", "name": "VLAN10_WEB", "password": "abc123", "port": 830, "state": "present", "username": "hp", "vlanid": "300" } }, "item": "v300", "msg": "ConnectionSSHError: host: 10.0.1.32, port: 830 msg: There was an error connecting with SSH. The NETCONF server may be down or refused the connection. The connection may have timed out if the server wasn't reachable."`

Since the hosts in my playbook is only pointing to the host [cmu.lab.net](http://cmu.lab.net) where im executing my tasks it seems to override me pointing to a different host in the tasks.  
I have also tried using a hardcoded ip. which is beeing replaced by the inventory\_hostname.  
So the module itself uses ssh for connection to the comware switches. Not working like some of the rest-api based modules. It seems to be relying on the normal ssh transport.  
So maybe the jumphost is what I really need.  
`

- name: C  
comware\_vlan:  
vlanid: “{{ item | regex\_search(‘[0-9]+’) }}”  
name: VLAN10\_WEB  
descr: “{{ switches.vlan\_descriptions[item] }}”  
username: “{{ switches.user }}”  
password: “{{ switches.password }}”  
hostname: 172.16.1.241  
with\_items: “{{ switches.vlans[switches.list[outer\_item].type] }}”

`
