FreeKB - Ansible --user command line option (SSH)
Ansible - --user command line option (SSH)

Let's say you have a playbook named foo.yml, and the playbook contains the following. The important thing to notice here is that the playbook does not include the remote_user parameter.

---
- hosts: all
  tasks:
    - name: store the stats of example.txt in the 'out' variable
      stat:
        path: /path/to/example.txt
      register: out

 

Let's say John Doe runs this playbook, targetting server1.example.com.

[john.doe@ansible1]# ansible-playbook foo.yml -i server1.example.com,

 

Running this playbook should return the following. Notice the output does not identify that john.doe made the SSH connection.

PLAY [all]

TASK [store the stats of example.txt in the 'out' variable] 
ok: [server2.example.com]

PLAY RECAP 
server2.example.com    : ok=1    changed=0    unreachable=0    failed=0 

 

The -vvv flag can be used to include some SSH output.

[john.doe@ansible1 ]# ansible-playbook foo.yml -i server1.example.com, -vvv

 

The following should be included in the output. In this example, "none" means that the user that invoked the playbook will be the SSH user.

<server1.example.com> ESTABLISH SSH CONNECTION FOR USER: None

 

The --user command line flag can be used to define the user that will be used when making an SSH connection to a managed node (e.g. the target system). The --user command line flag will take precedence over the remote_user parameter.

[john.doe@ansible1 ]# ansible-playbook foo.yml -i server1.example.com, --user jane.doe -vvv

 

Now, when the playbook is invoked with the --user and -vvv flag, jane.doe is identified as the SSH user.

<server1.example.com> ESTABLISH SSH CONNECTION FOR USER: jane.doe

 

The --user option is often used in tandem with the --ask-pass flag.

ansible-playbook foo.yml --user john.doe --ask-pass

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter f517d in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |