local_action: command rsync and {{ansible_ssh_user}}

I am running ansible 1.3.3.

I am trying to do an rsync of a set of directories to a remote machine.

This works:

local_action: command rsync -ae ssh /LOCAL_PATH kbyers@{{ansible_ssh_host}}:/REMOTE_PATH

But this doesn’t (only change is the ansible_ssh_user):

local_action: command rsync -ae ssh /LOCAL_PATH {{ansible_ssh_user}}@{{ansible_ssh_host}}:/REMOTE_PATH

/etc/ansible/hosts has ansible_ssh_user=kbyers defined for this host.

Should this not work?

When the command that fails, the rsync tries to use the local_user i.e. the user that I ran ansible-playbook as (I see in the output an SSH password prompt…local_user@remote_IP )

When reporting a bug, please explain the behavior of the “doesn’t work” case.

In the doesn’t work case the user that was used for the rsync SSH connection is not {{ansible_ssh_user}} instead it tried to use the local user that I ran the ansible-playbook as.

Kirk

Here are some more details:

Here is what my /etc/ansible/hosts looks like:

host1 ansible_ssh_host=X.X.X.X ansible_ssh_user=kbyers

Here is what the relevant section of my playbook looks like:

  • hosts: host1

tasks:

  • name: Sync code

local_action: command rsync -ae ssh /LOCAL_PATH {{ansible_ssh_user}}@{{ansible_ssh_host}}:/REMOTE_PATH

When I execute the above playbook, I receive an SSH password prompt asking me to login to the remote machine (for local_user@remote_IP:) where local_user is the user that I ran the playbook as (not user ‘kbyers’). If I change the above to kbyers@{{ansible_ssh_host}}:/REMOTE_PATH, the playbook executes correctly with no password required (i.e. using SSH authorized_keys).

Sounds like you need to set ansible_ssh_user in inventory to ‘kbeyers’.