Apologies in advance if this issue has been answered already.  My searches 
came up empty.

I have a playbook that uses multiple become users on each host.  I'd like 
to have the playbook work with whatever become method the caller wants to 
use.  I know the caller can use connection variables to define per-host 
become passwords, but is it possible to have passwords defined on a 
per-host/per-user basis?

Thanks,
Ed


[centos@testing ~]$ cat two_be.yml
---
- hosts: localhost
  tasks:
  - command: whoami
    register: who_is_user1
    become: true
    become_user: user1
  - debug:
      var: who_is_user1.stdout_lines
  - command: whoami
    register: who_is_user2
    become: true
    become_user: user2
  - debug:
      var: who_is_user2.stdout_lines
[centos@testing ~]$ ansible-playbook two_be.yml --become-method=sudo
 [WARNING]: provided hosts list is empty, only localhost is available


PLAY [localhost] 
***************************************************************

TASK [setup] 
*******************************************************************
ok: [localhost]

TASK [command] 
*****************************************************************
changed: [localhost]

TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "who_is_user1.stdout_lines": [
        "user1"
    ]
}

TASK [command] 
*****************************************************************
changed: [localhost]

TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "who_is_user2.stdout_lines": [
        "user2"
    ]
}

PLAY RECAP 
*********************************************************************
localhost                  : ok=5    changed=2    unreachable=0    failed=0

[centos@testing ~]$ ansible-playbook two_be.yml --become-method=su 
--ask-become-pass
SU password:
 [WARNING]: provided hosts list is empty, only localhost is available


PLAY [localhost] 
***************************************************************

TASK [setup] 
*******************************************************************
ok: [localhost]

TASK [command] 
*****************************************************************
changed: [localhost]

TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "who_is_user1.stdout_lines": [
        "user1"
    ]
}

TASK [command] 
*****************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, 
"module_stderr": "su: Authentication failure\n", "module_stdout": "", 
"msg": "MODULE FAILURE"}
        to retry, use: --limit @/home/centos/two_be.retry

PLAY RECAP 
*********************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=1

[centos@testing ~]$

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6658a04a-8b53-43ba-90c8-054e663c7f8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to