Ansible - remote_user parameter (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 remote_user parameter can be used to define what user will be used when making an SSH connection to a managed node (e.g. the target system). In this example, user jane.doe will be used in the SSH connection. Now, when john.doe invokes the ansible-playbook command, jane.doe will be the user that makes the SSH connection from server1.example.com to server1.example.com. 

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

 

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

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

 

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 jack.doe -vvv

 



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 a1133 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   |