Inventory groups with same hosts but differnts ansible_ssh_user

32 views
Skip to first unread message

Hervé Leclerc

unread,
Mar 18, 2014, 4:55:19 AM3/18/14
to ansible...@googlegroups.com
hello,
Here is a sample inventory that i want to use

[paadadm]
machine1   ansible_ssh_user=admin comment="Sandbox Admin Node"

[paadsrvwbsa]
machine1  ansible_ssh_user=doe comment="Sandbox Node A"

[paadsrvwbsb]
machine2 ansible_ssh_user=anotherone comment="Sandbox Node B"


[paadstack:children]
paadadm
paadsrvwbsa
paadsrvwbsb



if i use this  sample playbook 
---
- hosts: paadstack
  remote_user: '{{ ansible_ssh_user }}'

  tasks:
     - name: "hello"
       debug: msg="hello {{ ansible_ssh_user }}"

i get this output :

PLAY [paadstack] **************************************************************

GATHERING FACTS ***************************************************************
ok: [machine1]
ok: [machine2]

TASK: [hello] *****************************************************************
ok: [machine1] => {
    "msg": "hello doe"
}
ok: [machine2] => {
    "msg": "hello anotherone"
}


PLAY RECAP ********************************************************************
machine1                   : ok=2    changed=0    unreachable=0    failed=0
machine2                   : ok=2    changed=0    unreachable=0    failed=0


is it possible not to make an alias on machine1 to have 2 executions on machine1 because users are differents ? 

Hervé Leclerc

unread,
Mar 18, 2014, 5:01:13 AM3/18/14
to ansible...@googlegroups.com

Finally i've found the solution (thx to raphael) : make an inventory alias

[paadsrvwbsa]
machine1_alias ansible_ssh_host=machine1  ansible_ssh_user=doe comment="Sandbox Node A"
Reply all
Reply to author
Forward
0 new messages