ansible.posix icon indicating copy to clipboard operation
ansible.posix copied to clipboard

Synchronize wrong user and doesn't work

Open craph opened this issue 5 years ago • 5 comments
trafficstars

SUMMARY

I'm unable to use synchronize Ansible module to copy files from a server A to server B I'm using a shared user between thoses servers to authorize ssh connection without password by using ssh key. But when I launch the synchronize module it seems it's the wrong user that it is used in the dest...

ISSUE TYPE
  • Bug Report
COMPONENT NAME

synchronize

ANSIBLE VERSION
ansible 2.9.3
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
CONFIGURATION

OS / ENVIRONMENT

CentOS 7.7

STEPS TO REPRODUCE
- name: "Copy all files from {{ old_server }} to {{ inventory_hostname }}"
  synchronize:
    src: "{{ item }}"
    dest: "{{ item }}"
  delegate_to: "{{ old_server }}"
  become: yes
  become_user: "{{ my_shared_user }}"
  with_items:
    - "/tmp/toto"
  tags: copy_files
EXPECTED RESULTS

I should be able to copy files.

ACTUAL RESULTS

Now It seems the dest is wrong in the tmp python file

ANSIBALLZ_PARAMS = '{"ANSIBLE_MODULE_ARGS": {"_ansible_version": "2.9.3", "src": "/tmp/toto", "_ansible_syslog_facility": "LOG_USER", "_ansible_selinux_special_fs": ["fuse", "nfs", "vboxsf", "ramfs", "9p", "vfat"], "_ansible_no_log": false, "_local_rsync_path": "rsync", "dest": "root@old_server:/tmp/toto", "_ansible_module_name": "synchronize", "_ansible_remote_tmp": "$HOME/.ansible/tmp", "_ansible_verbosity": 4, "_ansible_keep_remote_files": false, "_local_rsync_password": null, "_ansible_socket": null, "_ansible_string_conversion_action": "warn", "_ansible_diff": false, "_ansible_debug": false, "_ansible_shell_executable": "/bin/sh", "_ansible_check_mode": false, "_ansible_tmpdir": null, "rsync_path": "sudo rsync"}}'

Why it's "root@old_server" instead of the user in the become_user ?

Thank you very much for your help.

craph avatar May 04 '20 13:05 craph

I have just try with the pull mode but I have something else strange :

- name: "Copy all data files from {{ old_server }} to {{ inventory_hostname }}"
  synchronize:
    mode: pull
    src: "{{ old_server }}:{{ item }}"
    dest: "/opt/data"
  become: yes
  become_user: "{{ my_user }}"
  with_items:
    - "{{ old_data_path }}/Variables.txt"
    - "{{ old_data_path }}/info.txt"

And in the play I can see :

failed: [myserver] (item=/opt/data/info.txt) => {
    "ansible_loop_var": "item", 
    "changed": false, 
    "cmd": "/bin/rsync --delay-updates -F --compress --archive --rsh=/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null --rsync-path=sudo rsync --out-format=<<CHANGED>>%i %n%L root@myserver:old_server:/opt/data/info.txt /opt/data", 
    "invocation": {
        "module_args": {
            "_local_rsync_password": null, 
            "_local_rsync_path": "rsync", 
            "_substitute_controller": false, 
            "archive": true, 
            "checksum": false, 
            "compress": true, 
            "copy_links": false, 
            "delete": false, 
            "dest": "/opt/data", 
            "dest_port": null, 
            "dirs": false, 
            "existing_only": false, 
            "group": null, 
            "link_dest": null, 
            "links": null, 
            "mode": "pull", 
            "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": "root@myserver:old_server:/opt/data/info.txt", 
            "ssh_args": null, 
            "times": null, 
            "verify_host": false
        }
    }, 
    "item": "/opt/data/info.txt", 
    "msg": "rsync: change_dir \"/root//old_server:/opt/data\" failed: No such file or directory (2)\nrsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1650) [Receiver=3.1.2]\nrsync: [Receiver] write error: Broken pipe (32)\n", 
    "rc": 23
}

I don't understand the field src...

craph avatar May 04 '20 13:05 craph

The only way to have this play working is to launch it with the correct user from my control machine.

Otherwise it doesn't work... It seems the escalation process has some bad behavior...

In my context with a Jenkins I had to do this to have this working :

- name: "Copy all data files from {{ old_server }} to {{ inventory_hostname }}"
  synchronize:
    mode: push
    src: "{{ item }}"
    dest: "/opt/data"
  become: yes
  become_user: "{{ my_user }}"
  become_method: su
  become_flags: '-'
  delegate_to: "{{ old_server }}"
  with_items:
    - "{{ old_data_path }}/Variables.txt"
    - "{{ old_data_path }}/info.txt"

Why I have to had : become_method: su become_flags: '-'

craph avatar May 05 '20 08:05 craph

Hello, try to add the following parameter in your task:

set_remote_user: false

guerzon avatar Jun 18 '20 08:06 guerzon

See #60 - this may be related

djgraff209 avatar Jun 24 '20 12:06 djgraff209

+1

schmavid avatar Feb 19 '21 17:02 schmavid