bcoca / local_backup

role that allows copying/moving remote backup_file to controller dir by config
GNU General Public License v3.0
3 stars 0 forks source link

Still no backup files created in $ANSIBLE_LOCAL_BACKUP #3

Closed fthommen closed 2 years ago

fthommen commented 2 years ago

Hi,

this refers to #2. Thanks for the hint there. Unfortunately even with the environment variable $ANSIBLE_LOCAL_BACKUP set, I can't get this to work.

My playbooks looks like:

- hosts: localhost
  gather_facts: false
  environment:
    ANSIBLE_LOCAL_BACKUP: /tmp/mybackups
  roles:
    - local_backup

- hosts: mypc
  tasks:
    - copy: backup=yes src=testfile dest=testfile2
      environment:
        ANSIBLE_LOCAL_BACKUP: /tmp/mybackups

I run this as ansible-playbook local_backup.yml --user=root or ansible-playbook local_backup.yml --limit=mypc --user=root. However after a few runs with various testfiles, I get the following situation on mypc:

[root@mypc ~]# ls -l ~ | grep testfile
-rw-r--r--. 1 root root    25 Aug 11 10:28 testfile2
-rw-r--r--. 1 root root    14 Aug 11 10:26 testfile2.13816.2022-08-11@10:27:08~
-rw-r--r--. 1 root root    24 Aug 11 10:27 testfile2.14577.2022-08-11@10:28:16~
-rw-r--r--. 1 root root    35 Aug 11 10:28 testfile2.15323.2022-08-11@10:28:45~
[root@mypc ~]# ls -l /tmp/mybackups
ls: cannot access /tmp/mybackups: No such file or directory
[root@mypc ~]# 

this is the output with -vvv:

$ ansible-playbook -vvv local_backup.yml  --user=root
ansible-playbook 2.9.27
  config file = /data/homes/ansible/ansible-config/ft/test-local-backup/ansible.cfg
  configured module search path = [u'/data/homes/ansible/ansible-config/ft/test-local-backup/library']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
Using /data/homes/ansible/ansible-config/ft/test-local-backup/ansible.cfg as config file
host_list declined parsing /data/homes/ansible/ansible-config/ft/test-local-backup/ansible-hosts as it did not pass its verify_file() method
script declined parsing /data/homes/ansible/ansible-config/ft/test-local-backup/ansible-hosts as it did not pass its verify_file() method
auto declined parsing /data/homes/ansible/ansible-config/ft/test-local-backup/ansible-hosts as it did not pass its verify_file() method
Parsed /data/homes/ansible/ansible-config/ft/test-local-backup/ansible-hosts inventory source with ini plugin
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'full_skip', as we already have a stdout callback.
Skipping callback 'json', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'null', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Skipping callback 'selective', as we already have a stdout callback.
Skipping callback 'skippy', as we already have a stdout callback.
Skipping callback 'stderr', as we already have a stdout callback.
Skipping callback 'unixy', as we already have a stdout callback.
Skipping callback 'yaml', as we already have a stdout callback.

PLAYBOOK: local_backup.yml *******************************************************************************************************************************************************************************
2 plays in local_backup.yml

PLAY [localhost] *****************************************************************************************************************************************************************************************
META: ran handlers
META: ran handlers
META: ran handlers

PLAY [mypc] *****************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************
task path: /data/homes/ansible/ansible-config/ft/test-local-backup/local_backup.yml:8
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''
<mypc> (0, '/root\n', '')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1660206945.75-53312-23665521108871 `" && echo ansible-tmp-1660206945.75-53312-23665521108871="` echo /root/.ansible/tmp/ansible-tmp-1660206945.75-53312-23665521108871 `" ) && sleep 0'"'"''
<mypc> (0, 'ansible-tmp-1660206945.75-53312-23665521108871=/root/.ansible/tmp/ansible-tmp-1660206945.75-53312-23665521108871\n', '')
<mypc> Attempting python interpreter discovery
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'echo PLATFORM; uname; echo FOUND; command -v '"'"'"'"'"'"'"'"'/usr/bin/python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.6'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.5'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python2.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python2.6'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/libexec/platform-python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python3'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python'"'"'"'"'"'"'"'"'; echo ENDFOUND && sleep 0'"'"''
<mypc> (0, 'PLATFORM\nLinux\nFOUND\n/usr/bin/python\n/usr/bin/python3.6\n/usr/bin/python2.7\n/usr/libexec/platform-python\n/usr/bin/python3\n/usr/bin/python\nENDFOUND\n', '')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'/usr/bin/python && sleep 0'"'"''
<mypc> (0, '{"osrelease_content": "NAME=\\"CentOS Linux\\"\\nVERSION=\\"7 (Core)\\"\\nID=\\"centos\\"\\nID_LIKE=\\"rhel fedora\\"\\nVERSION_ID=\\"7\\"\\nPRETTY_NAME=\\"CentOS Linux 7 (Core)\\"\\nANSI_COLOR=\\"0;31\\"\\nCPE_NAME=\\"cpe:/o:centos:centos:7\\"\\nHOME_URL=\\"https://www.centos.org/\\"\\nBUG_REPORT_URL=\\"https://bugs.centos.org/\\"\\n\\nCENTOS_MANTISBT_PROJECT=\\"CentOS-7\\"\\nCENTOS_MANTISBT_PROJECT_VERSION=\\"7\\"\\nREDHAT_SUPPORT_PRODUCT=\\"centos\\"\\nREDHAT_SUPPORT_PRODUCT_VERSION=\\"7\\"\\n\\n", "platform_dist_result": ["centos", "7.9.2009", "Core"]}\n', '')
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/setup.py
<mypc> PUT /home/thommen/.ansible/tmp/ansible-local-53296t9JriF/tmpe0BaBs TO /root/.ansible/tmp/ansible-tmp-1660206945.75-53312-23665521108871/AnsiballZ_setup.py
<mypc> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 '[mypc]'
<mypc> (0, 'sftp> put /home/thommen/.ansible/tmp/ansible-local-53296t9JriF/tmpe0BaBs /root/.ansible/tmp/ansible-tmp-1660206945.75-53312-23665521108871/AnsiballZ_setup.py\n', '')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1660206945.75-53312-23665521108871/ /root/.ansible/tmp/ansible-tmp-1660206945.75-53312-23665521108871/AnsiballZ_setup.py && sleep 0'"'"''
<mypc> (0, '', '')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 -tt mypc '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1660206945.75-53312-23665521108871/AnsiballZ_setup.py && sleep 0'"'"''
<mypc> (0, '\r\n{"invocation": {"module_args": {"filter": "*", "gather_subset": ["min"], "fact_path": "/etc/ansible/facts.d", "gather_timeout": 10}}, "ansible_facts": {"ansible_distribution_file_parsed": true, "ansible_fips": false, "ansible_service_mgr": "systemd", "ansible_user_id": "root", "module_setup": true, "gather_subset": ["min"], "ansible_ssh_host_key_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJaaRKIu334Nuah3meHRx+Vvyme8l4CzgIe9sgVmPYcXqMzVns+CQ+9qV/LTexknsc2KkJ0ifC6NId+tFBenR20=", "ansible_kernel_version": "#1 SMP Tue Jun 28 15:37:28 UTC 2022", "ansible_distribution_version": "7.9", "ansible_domain": "inet.dkfz-heidelberg.de", "ansible_distribution_file_path": "/etc/redhat-release", "ansible_date_time": {"weekday_number": "4", "iso8601_basic_short": "20220811T103547", "tz": "CEST", "weeknumber": "32", "hour": "10", "year": "2022", "minute": "35", "tz_offset": "+0200", "month": "08", "epoch": "1660206947", "iso8601_micro": "2022-08-11T08:35:47.488131Z", "weekday": "Thursday", "time": "10:35:47", "date": "2022-08-11", "iso8601": "2022-08-11T08:35:47Z", "day": "11", "iso8601_basic": "20220811T103547488131", "second": "47"}, "ansible_ssh_host_key_ed25519_public": "AAAAC3NzaC1lZDI1NTE5AAAAIHBh1pvKLdxo8WW6GbWuphq1W1X0NfyVM+eMiWqrLMrW", "ansible_distribution_file_variety": "RedHat", "ansible_dns": {"nameservers": ["192.55.188.177", "192.55.188.199"], "search": ["dkfz-heidelberg.de", "inet.dkfz-heidelberg.de"]}, "ansible_effective_group_id": 0, "ansible_userspace_bits": "64", "ansible_architecture": "x86_64", "ansible_real_user_id": 0, "ansible_distribution_release": "Core", "ansible_apparmor": {"status": "disabled"}, "ansible_cmdline": {"LANG": "en_US.UTF-8", "plymouth.ignore-udev": true, "BOOT_IMAGE": "/boot/vmlinuz-3.10.0-1160.71.1.el7.x86_64", "quiet": true, "nouveau.modeset": "0", "rhgb": true, "rd.driver.blacklist": "nouveau", "crashkernel": "auto", "ro": true, "root": "UUID=5a41605d-7382-4554-a63f-c224a68392cd"}, "ansible_effective_user_id": 0, "ansible_machine_id": "1769692c0fd44c11b43c91382ffd0748", "ansible_os_family": "RedHat", "ansible_userspace_architecture": "x86_64", "ansible_pkg_mgr": "yum", "ansible_user_uid": 0, "ansible_distribution": "CentOS", "ansible_user_dir": "/root", "ansible_env": {"SSH_ASKPASS": "/usr/libexec/openssh/gnome-ssh-askpass", "MODULE_VERSION": "3.2.10", "LESSOPEN": "||/usr/bin/lesspipe.sh %s", "SSH_CLIENT": "10.131.196.6 38806 22", "SELINUX_USE_CURRENT_RANGE": "", "LOGNAME": "root", "USER": "root", "QTDIR": "/usr/lib64/qt-3.3", "PATH": "/usr/lib64/qt-3.3/bin:/usr/sbin:/usr/bin:/sbin:/bin:/software/bin:/opt/dell/srvadmin/sbin", "DISPLAY": "localhost:11.0", "QT_PLUGIN_PATH": "/usr/lib64/kde4/plugins:/usr/lib/kde4/plugins", "LANG": "en_US.UTF-8", "QTLIB": "/usr/lib64/qt-3.3/lib", "TERM": "xterm-256color", "SHELL": "/bin/bash", "QTINC": "/usr/lib64/qt-3.3/include", "HOME": "/root", "XDG_RUNTIME_DIR": "/run/user/0", "modules_shell": "bash", "SELINUX_ROLE_REQUESTED": "", "XDG_DATA_DIRS": "/root/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share", "QT_GRAPHICSSYSTEM_CHECKED": "1", "XDG_SESSION_ID": "386", "_": "/usr/bin/python", "MODULEPATH": "/tbi/software/modules/packages:/tbi/software/modules/meta_modules:/software/.modules/sw:/software/.modules/meta", "KDEDIRS": "/usr", "SSH_CONNECTION": "10.131.196.6 38806 193.174.51.189 22", "SSH_TTY": "/dev/pts/1", "SELINUX_LEVEL_REQUESTED": "", "SHLVL": "2", "PWD": "/root", "MAIL": "/var/mail/root", "LS_COLORS": "rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:", "BASH_FUNC_module()": "() {  eval `/tbi/software/x86_64/modules/modules-$MODULE_VERSION/el7/Modules/$MODULE_VERSION/bin/modulecmd $modules_shell $*`\\n}"}, "ansible_distribution_major_version": "7", "ansible_selinux_python_present": true, "ansible_hostname": "mypc", "ansible_real_group_id": 0, "ansible_lsb": {"release": "7.9.2009", "major_release": "7", "codename": "Core", "id": "CentOS", "description": "CentOS Linux release 7.9.2009 (Core)"}, "ansible_proc_cmdline": {"LANG": "en_US.UTF-8", "plymouth.ignore-udev": true, "BOOT_IMAGE": "/boot/vmlinuz-3.10.0-1160.71.1.el7.x86_64", "quiet": true, "nouveau.modeset": "0", "rhgb": true, "rd.driver.blacklist": "nouveau", "crashkernel": "auto", "ro": true, "root": "UUID=5a41605d-7382-4554-a63f-c224a68392cd"}, "ansible_local": {}, "ansible_machine": "x86_64", "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDX7BwFZvM7zbgBLmE55AiMA79P+BiLsrLaHOEOQUzWCq+c5azUYxBenBXhacVD1LC4YaRgcmX0u74MGgV/TSrfEEDsIOmNxImzowylrTko8zyZB8cNLqHskyI6YZvyTBAr+KjUD6/ILwVlyEzpa1ktOFVOr8s9Dkvw4BH6SHs+eI0JdC/nT8j3qEygpTHxa03v2TwOsqwF1BaMu7dRY5MS+HoHbeya7jUTnJK2isPsMrREiRQMv2pHRubL93vpFixrIklTPAtt7cvxuvlOcOHvrWDvaf1rg+sH5Sj1kbwHJaPg8lwu7tlVSFIYNxmalCn5BG8RaWzatGLGJUmZgsAD", "ansible_system_capabilities_enforced": "True", "ansible_user_gecos": "root", "ansible_system_capabilities": ["cap_chown", "cap_dac_override", "cap_dac_read_search", "cap_fowner", "cap_fsetid", "cap_kill", "cap_setgid", "cap_setuid", "cap_setpcap", "cap_linux_immutable", "cap_net_bind_service", "cap_net_broadcast", "cap_net_admin", "cap_net_raw", "cap_ipc_lock", "cap_ipc_owner", "cap_sys_module", "cap_sys_rawio", "cap_sys_chroot", "cap_sys_ptrace", "cap_sys_pacct", "cap_sys_admin", "cap_sys_boot", "cap_sys_nice", "cap_sys_resource", "cap_sys_time", "cap_sys_tty_config", "cap_mknod", "cap_lease", "cap_audit_write", "cap_audit_control", "cap_setfcap", "cap_mac_override", "cap_mac_admin", "cap_syslog", "35", "36+ep"], "ansible_python": {"executable": "/usr/bin/python", "version": {"micro": 5, "major": 2, "releaselevel": "final", "serial": 0, "minor": 7}, "type": "CPython", "has_sslcontext": true, "version_info": [2, 7, 5, "final", 0]}, "ansible_selinux": {"status": "enabled", "policyvers": 31, "type": "targeted", "mode": "permissive", "config_mode": "permissive"}, "ansible_fqdn": "mypc.inet.dkfz-heidelberg.de", "ansible_user_gid": 0, "ansible_python_version": "2.7.5", "ansible_system": "Linux", "ansible_user_shell": "/bin/bash", "ansible_kernel": "3.10.0-1160.71.1.el7.x86_64", "ansible_nodename": "mypc"}}\r\n', 'Shared connection to mypc closed.\r\n')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1660206945.75-53312-23665521108871/ > /dev/null 2>&1 && sleep 0'"'"''
<mypc> (0, '', '')
ok: [mypc]
META: ran handlers

TASK [copy] **********************************************************************************************************************************************************************************************
task path: /data/homes/ansible/ansible-config/ft/test-local-backup/local_backup.yml:10
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''
<mypc> (0, '/root\n', '')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574 `" && echo ansible-tmp-1660206947.89-53344-17556763397574="` echo /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574 `" ) && sleep 0'"'"''
<mypc> (0, 'ansible-tmp-1660206947.89-53344-17556763397574=/root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574\n', '')
Using module file /usr/lib/python2.7/site-packages/ansible/modules/files/stat.py
<mypc> PUT /home/thommen/.ansible/tmp/ansible-local-53296t9JriF/tmpvSf4we TO /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/AnsiballZ_stat.py
<mypc> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 '[mypc]'
<mypc> (0, 'sftp> put /home/thommen/.ansible/tmp/ansible-local-53296t9JriF/tmpvSf4we /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/AnsiballZ_stat.py\n', '')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/ /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/AnsiballZ_stat.py && sleep 0'"'"''
<mypc> (0, '', '')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 -tt mypc '/bin/sh -c '"'"'ANSIBLE_LOCAL_BACKUP=/tmp/mybackups /usr/bin/python /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/AnsiballZ_stat.py && sleep 0'"'"''
<mypc> (0, '\r\n{"invocation": {"module_args": {"checksum_algorithm": "sha1", "get_checksum": true, "follow": false, "path": "testfile2", "get_md5": false, "get_mime": true, "get_attributes": true}}, "stat": {"charset": "us-ascii", "uid": 0, "exists": true, "attr_flags": "e", "woth": false, "isreg": true, "device_type": 0, "mtime": 1660206916.1210828, "block_size": 4096, "inode": 1450149, "isgid": false, "size": 41, "executable": false, "isuid": false, "readable": true, "version": "18446744072947325335", "pw_name": "root", "gid": 0, "ischr": false, "wusr": true, "writeable": true, "mimetype": "text/plain", "blocks": 8, "xoth": false, "islnk": false, "nlink": 1, "issock": false, "rgrp": true, "gr_name": "root", "path": "testfile2", "xusr": false, "atime": 1660206916.1210828, "isdir": false, "ctime": 1660206916.125083, "isblk": false, "wgrp": false, "checksum": "aea9d2fd51373c0065354a0b5167b374f4784ba9", "dev": 2049, "roth": true, "isfifo": false, "mode": "0644", "xgrp": false, "rusr": true, "attributes": ["extents"]}, "changed": false}\r\n', 'Shared connection to mypc closed.\r\n')
<mypc> PUT /data/homes/ansible/ansible-config/ft/test-local-backup/testfile TO /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/source
<mypc> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 '[mypc]'
<mypc> (0, 'sftp> put /data/homes/ansible/ansible-config/ft/test-local-backup/testfile /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/source\n', '')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/ /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/source && sleep 0'"'"''
<mypc> (0, '', '')
Using module file /usr/lib/python2.7/site-packages/ansible/modules/files/copy.py
<mypc> PUT /home/thommen/.ansible/tmp/ansible-local-53296t9JriF/tmpIIdhz5 TO /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/AnsiballZ_copy.py
<mypc> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 '[mypc]'
<mypc> (0, 'sftp> put /home/thommen/.ansible/tmp/ansible-local-53296t9JriF/tmpIIdhz5 /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/AnsiballZ_copy.py\n', '')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/ /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/AnsiballZ_copy.py && sleep 0'"'"''
<mypc> (0, '', '')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 -tt mypc '/bin/sh -c '"'"'ANSIBLE_LOCAL_BACKUP=/tmp/mybackups /usr/bin/python /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/AnsiballZ_copy.py && sleep 0'"'"''
<mypc> (0, '\r\n{"src": "/root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/source", "md5sum": "495805a3ac6b4780053ea24f1b9a6d37", "backup_file": "./testfile2.16301.2022-08-11@10:35:50~", "uid": 0, "dest": "./testfile2", "checksum": "4cc7fefc2bc81d6980470fd1fe43b27f5d0484fb", "changed": true, "owner": "root", "state": "file", "gid": 0, "secontext": "unconfined_u:object_r:admin_home_t:s0", "mode": "0644", "invocation": {"module_args": {"directory_mode": null, "force": true, "remote_src": null, "_original_basename": "testfile", "owner": null, "follow": false, "local_follow": null, "group": null, "unsafe_writes": false, "setype": null, "content": null, "serole": null, "dest": "./testfile2", "selevel": null, "regexp": null, "validate": null, "src": "/root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/source", "checksum": "4cc7fefc2bc81d6980470fd1fe43b27f5d0484fb", "seuser": null, "delimiter": null, "mode": null, "attributes": null, "backup": true}}, "group": "root", "size": 46}\r\n', 'Shared connection to mypc closed.\r\n')
<mypc> ESTABLISH SSH CONNECTION FOR USER: root
<mypc> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/home/thommen/.ansible/cp/4f50b4ee53 mypc '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/ > /dev/null 2>&1 && sleep 0'"'"''
<mypc> (0, '', '')
changed: [mypc] => changed=true 
  backup_file: ./testfile2.16301.2022-08-11@10:35:50~
  checksum: 4cc7fefc2bc81d6980470fd1fe43b27f5d0484fb
  dest: ./testfile2
  diff: []
  gid: 0
  group: root
  invocation:
    module_args:
      _original_basename: testfile
      attributes: null
      backup: true
      checksum: 4cc7fefc2bc81d6980470fd1fe43b27f5d0484fb
      content: null
      delimiter: null
      dest: ./testfile2
      directory_mode: null
      follow: false
      force: true
      group: null
      local_follow: null
      mode: null
      owner: null
      regexp: null
      remote_src: null
      selevel: null
      serole: null
      setype: null
      seuser: null
      src: /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/source
      unsafe_writes: false
      validate: null
  md5sum: 495805a3ac6b4780053ea24f1b9a6d37
  mode: '0644'
  owner: root
  secontext: unconfined_u:object_r:admin_home_t:s0
  size: 46
  src: /root/.ansible/tmp/ansible-tmp-1660206947.89-53344-17556763397574/source
  state: file
  uid: 0
META: ran handlers
META: ran handlers

PLAY RECAP ***********************************************************************************************************************************************************************************************
mypc                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
$

HTH

fthommen commented 2 years ago

Is there by chance any update @bcoca ?

bcoca commented 2 years ago

The issue is you are working on the controller, so 'remote' setting is not going to work, you need to invoke ansible with the env var already set:

ANSIBLE_LOCAL_BACKUP=/tmp/mybackups ansible-playbook ...

fthommen commented 2 years ago

Thanks @bcoca. It seems that I completely misunderstood what local_backup does. It seems to create the backup files on the controller and not on the client. That's not what I tried to achieve. We would need the backup files to stay on the client, but in a dedicated (backup) directory tree and not in the original directory (to avoid clutter with sometimes hundreds of backup files). So I will probably have to look for an other solution.

bcoca commented 2 years ago

@fthommen that is the reason we have not built this into Ansible itself, many different needs and requirements on what the backup location needs to be for people, but this can be used as an example to develop your own.

For yoru case i suggest a role that just does 'copy: remote_src=true+file: state=absetusing{{backup_file}}` returned from the task.