Sample Header Ad - 728x90

Ansible synchronize module is not replacing user variable with exact user name

-1 votes
2 answers
374 views
I tried many ways to fix the below problem, but I was not lucky enough. I have the below inventories; #cat inventory/common/group_vars/all/inventory_pwd.yml remote1_user: "devops" #cat inventory/nonprod/fdc/group_vars/all/inventory.txt [remote] x.x.x.x ansible_ssh_user="{{ remote1_user }}" ansible_port=22 ansible_password="test@12" And I am running this below playbook to copy files from control machine to a remote machine; pb.yml
---
- name: "Copy test"
  hosts: remote
  become: true
  tasks:

    - name: Copying content to the remote vm
      synchronize:
        src: /ansible/playbooks/Hello
        dest: /home/devops/
      delegate_to: localhost
In the controller machine I logged as root user, and the user to connect with remote server is devops. But, after executing the playbook I am getting the below error; ansible-playbook -vvv -i inventory/common -i inventory/nonprod/fdc/group_vars/all/inventory.txt pb.yml
TASK [Copying content to the remote vm] *********************************************************************************************task path: /ansible/playbooks/pb.yml:9
fatal: [x.x.x.x -> localhost]: FAILED! => {
    "changed": false,
    "cmd": "sshpass -d3 /usr/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null --rsync-path=sudo rsync --out-format=>%i %n%L /ansible/playbooks/Hello {{remote1_user}}@x.x.x.x:/home/devops/",
    "invocation": {
        "module_args": {
            "_local_rsync_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "_local_rsync_path": "rsync",
            "_substitute_controller": false,
            "archive": true,
            "checksum": false,
            "compress": true,
            "copy_links": false,
            "delete": false,
            "dest": "{{remote1_user}}@x.x.x.x:/home/devops/",
            "dest_port": null,
            "dirs": false,
            "existing_only": false,
            "group": null,
            "link_dest": null,
            "links": null,
            "mode": "push",
            "owner": null,
            "partial": false,
            "perms": null,
            "private_key": null,
            "recursive": null,
            "rsync_opts": [],
            "rsync_path": "sudo rsync",
            "rsync_timeout": 0,
            "set_remote_user": true,
            "src": "/ansible/playbooks/Hello",
            "ssh_args": null,
            "times": null,
            "verify_host": false
        }
    },
    "msg": "remote username contains invalid characters\r\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]\n",
    "rc": 255
}
Here the '"dest": "{{ remote1_user }}@x.x.x.x:/home/devops/"' should be like 'devops@x.x.x.x:/home/devops/'. However, it is not replacing 'remote1_user' with 'devops'. Can anyone please help me on this?
Asked by aneeshdevcube (21 rep)
Feb 24, 2024, 10:58 AM
Last activity: Apr 13, 2025, 06:43 AM