I am trying to rename a folder on a remote if it exists. this is being done via 
a role.

====== my two tasks 
===============================================================
- name: move legacy postgres - stat postgres_data
  stat: path="{{ postgres_data }}"
  register: postgres_data

- name: move legacy postgres - rename $PGDATA to 
/opt/db/data/postgres/data_legacy
  command: mv "{{ postgres_data }}" "{{ postgres_data_legacy }}"
  when: postgres_data.stat.exists
===================================================================================

the mv command fails if I am using variables as above. 
When I use hard-coded locations the mv operation is being executed as expected


====== defaults file (excerpt) 
====================================================
ansible_become_user: postgres
...
...
postgres_data: /opt/db/data/postgres/data
postgres_data_legacy: /opt/db/data/postgres/data_legacy 
...
===================================================================================

generally the tasks/main.yaml file seems to be able to get values from the 
defaults/main.yml
Still fot the operation at hand here I am getting this error:

====== error TASK 2 
===============================================================

TASK [postgres_disable : move legacy postgres - rename $PGDATA to 
/opt/db/data/postgres/data_legacy] ******************************
task path: 
/home/gwagner/repos/ansible/open_source/postgres_upgrade/roles/postgres_disable/tasks/main.yml:31
<rhel8-vm.local> ESTABLISH SSH CONNECTION FOR USER: None
<rhel8-vm.local> 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 ConnectTimeout=10 -o 
'ControlPath="/home/gwagner/.ansible/cp/e2fa0cd750"' rhel8-vm.local '/bin/sh -c 
'"'"'echo ~ && sleep 0'"'"''
<rhel8-vm.local> (0, b'/home/gwagner\n', b'')
<rhel8-vm.local> ESTABLISH SSH CONNECTION FOR USER: None
<rhel8-vm.local> 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 ConnectTimeout=10 -o 
'ControlPath="/home/gwagner/.ansible/cp/e2fa0cd750"' rhel8-vm.local '/bin/sh -c 
'"'"'( umask 77 && mkdir -p "` echo /var/tmp `"&& mkdir "` echo 
/var/tmp/ansible-tmp-1659080275.14459-73519-46884224045778 `" && echo 
ansible-tmp-1659080275.14459-73519-46884224045778="` echo 
/var/tmp/ansible-tmp-1659080275.14459-73519-46884224045778 `" ) && sleep 0'"'"''
<rhel8-vm.local> (0, 
b'ansible-tmp-1659080275.14459-73519-46884224045778=/var/tmp/ansible-tmp-1659080275.14459-73519-46884224045778\n',
 b'')
Using module file /usr/lib/python3.8/site-packages/ansible/modules/command.py
<rhel8-vm.local> PUT 
/home/gwagner/.ansible/tmp/ansible-local-73486ma2inx7k/tmpiwfg83t2 TO 
/var/tmp/ansible-tmp-1659080275.14459-73519-46884224045778/AnsiballZ_command.py
<rhel8-vm.local> 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 ConnectTimeout=10 -o 
'ControlPath="/home/gwagner/.ansible/cp/e2fa0cd750"' '[rhel8-vm.local]'
<rhel8-vm.local> (0, b'sftp> put 
/home/gwagner/.ansible/tmp/ansible-local-73486ma2inx7k/tmpiwfg83t2 
/var/tmp/ansible-tmp-1659080275.14459-73519-46884224045778/AnsiballZ_command.py\n',
 b'')
<rhel8-vm.local> ESTABLISH SSH CONNECTION FOR USER: None
<rhel8-vm.local> 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 ConnectTimeout=10 -o 
'ControlPath="/home/gwagner/.ansible/cp/e2fa0cd750"' rhel8-vm.local '/bin/sh -c 
'"'"'setfacl -m u:postgres:r-x 
/var/tmp/ansible-tmp-1659080275.14459-73519-46884224045778/ 
/var/tmp/ansible-tmp-1659080275.14459-73519-46884224045778/AnsiballZ_command.py 
&& sleep 0'"'"''
<rhel8-vm.local> (0, b'', b'')
<rhel8-vm.local> ESTABLISH SSH CONNECTION FOR USER: None
<rhel8-vm.local> 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 ConnectTimeout=10 -o 
'ControlPath="/home/gwagner/.ansible/cp/e2fa0cd750"' -tt rhel8-vm.local 
'/bin/sh -c '"'"'sudo -H -S -n  -u postgres /bin/sh -c '"'"'"'"'"'"'"'"'echo 
BECOME-SUCCESS-skhgpuwntdrihakvoaoaltlnpjlrzmat ; /usr/libexec/platform-python 
/var/tmp/ansible-tmp-1659080275.14459-73519-46884224045778/AnsiballZ_command.py'"'"'"'"'"'"'"'"'
 && sleep 0'"'"''
Escalation succeeded
<rhel8-vm.local> (1, b'\r\n{"changed": true, "stdout": "", "stderr": "mv: 
cannot stat \'{\'\\\\\'\'changed\'\\\\\'\': False, \'\\\\\'\'stat\'\\\\\'\': 
{\'\\\\\'\'exists\'\\\\\'\': True, \'\\\\\'\'path\'\\\\\'\': 
\'\\\\\'\'/opt/db/data/postgres/data\'\\\\\'\', \'\\\\\'\'mode\'\\\\\'\': 
\'\\\\\'\'0750\'\\\\\'\', \'\\\\\'\'isdir\'\\\\\'\': True, 
\'\\\\\'\'ischr\'\\\\\'\': False, \'\\\\\'\'isblk\'\\\\\'\': False, 
\'\\\\\'\'isreg\'\\\\\'\': False, \'\\\\\'\'isfifo\'\\\\\'\': False, 
\'\\\\\'\'islnk\'\\\\\'\': False, \'\\\\\'\'issock\'\\\\\'\': False, 
\'\\\\\'\'uid\'\\\\\'\': 1001, \'\\\\\'\'gid\'\\\\\'\': 1001, 
\'\\\\\'\'size\'\\\\\'\': 4096, \'\\\\\'\'inode\'\\\\\'\': 65664, 
\'\\\\\'\'dev\'\\\\\'\': 64779, \'\\\\\'\'nlink\'\\\\\'\': 20, 
\'\\\\\'\'atime\'\\\\\'\': 1659080065.949395, \'\\\\\'\'mtime\'\\\\\'\': 
1659017614.6222425, \'\\\\\'\'ctime\'\\\\\'\': 1659080076.9242337, 
\'\\\\\'\'wusr\'\\\\\'\': True, \'\\\\\'\'rusr\'\\\\\'\': True, 
\'\\\\\'\'xusr\'\\\\\'\': True, \'\\\\\'\'wgrp\'\\\\
 \'\': False, \'\\\\\'\'rgrp\'\\\\\'\': True, \'\\\\\'\'xgrp\'\\\\\'\': True, 
\'\\\\\'\'woth\'\\\\\'\': False, \'\\\\\'\'roth\'\\\\\'\': False, 
\'\\\\\'\'xoth\'\\\\\'\': False, \'\\\\\'\'isuid\'\\\\\'\': False, 
\'\\\\\'\'isgid\'\\\\\'\': False, \'\\\\\'\'blocks\'\\\\\'\': 8, 
\'\\\\\'\'block_size\'\\\\\'\': 4096, \'\\\\\'\'device_type\'\\\\\'\': 0, 
\'\\\\\'\'readable\'\\\\\'\': False, \'\\\\\'\'writeable\'\\\\\'\': False, 
\'\\\\\'\'executable\'\\\\\'\': False, \'\\\\\'\'pw_name\'\\\\\'\': 
\'\\\\\'\'postgres\'\\\\\'\', \'\\\\\'\'gr_name\'\\\\\'\': 
\'\\\\\'\'postgres\'\\\\\'\', \'\\\\\'\'mimetype\'\\\\\'\': 
\'\\\\\'\'inode/directory\'\\\\\'\', \'\\\\\'\'charset\'\\\\\'\': 
\'\\\\\'\'binary\'\\\\\'\', \'\\\\\'\'version\'\\\\\'\': None, 
\'\\\\\'\'attributes\'\\\\\'\': [], \'\\\\\'\'attr_flags\'\\\\\'\': 
\'\\\\\'\'\'\\\\\'\'}, \'\\\\\'\'failed\'\\\\\'\': False}\': No such file or 
directory", "rc": 1, "cmd": ["mv", "{\'changed\': False, \'stat\': {\'exists\': 
True, \'path\': \'/opt/db/data/p
 ostgres/data\', \'mode\': \'0750\', \'isdir\': True, \'ischr\': False, 
\'isblk\': False, \'isreg\': False, \'isfifo\': False, \'islnk\': False, 
\'issock\': False, \'uid\': 1001, \'gid\': 1001, \'size\': 4096, \'inode\': 
65664, \'dev\': 64779, \'nlink\': 20, \'atime\': 1659080065.949395, \'mtime\': 
1659017614.6222425, \'ctime\': 1659080076.9242337, \'wusr\': True, \'rusr\': 
True, \'xusr\': True, \'wgrp\': False, \'rgrp\': True, \'xgrp\': True, 
\'woth\': False, \'roth\': False, \'xoth\': False, \'isuid\': False, \'isgid\': 
False, \'blocks\': 8, \'block_size\': 4096, \'device_type\': 0, \'readable\': 
False, \'writeable\': False, \'executable\': False, \'pw_name\': \'postgres\', 
\'gr_name\': \'postgres\', \'mimetype\': \'inode/directory\', \'charset\': 
\'binary\', \'version\': None, \'attributes\': [], \'attr_flags\': \'\'}, 
\'failed\': False}", "/opt/db/data/postgres/data_legacy"], "start": "2022-07-29 
09:37:55.631096", "end": "2022-07-29 09:37:55.635130", "delta": 
"0:00:00.004034", "f
 ailed": true, "msg": "non-zero return code", "invocation": {"module_args": 
{"_raw_params": "mv \\"{\'changed\': False, \'stat\': {\'exists\': True, 
\'path\': \'/opt/db/data/postgres/data\', \'mode\': \'0750\', \'isdir\': True, 
\'ischr\': False, \'isblk\': False, \'isreg\': False, \'isfifo\': False, 
\'islnk\': False, \'issock\': False, \'uid\': 1001, \'gid\': 1001, \'size\': 
4096, \'inode\': 65664, \'dev\': 64779, \'nlink\': 20, \'atime\': 
1659080065.949395, \'mtime\': 1659017614.6222425, \'ctime\': 
1659080076.9242337, \'wusr\': True, \'rusr\': True, \'xusr\': True, \'wgrp\': 
False, \'rgrp\': True, \'xgrp\': True, \'woth\': False, \'roth\': False, 
\'xoth\': False, \'isuid\': False, \'isgid\': False, \'blocks\': 8, 
\'block_size\': 4096, \'device_type\': 0, \'readable\': False, \'writeable\': 
False, \'executable\': False, \'pw_name\': \'postgres\', \'gr_name\': 
\'postgres\', \'mimetype\': \'inode/directory\', \'charset\': \'binary\', 
\'version\': None, \'attributes\': [], \'attr_flags\
 ': \'\'}, \'failed\': False}\\" \\"/opt/db/data/postgres/data_legacy\\"", 
"_uses_shell": false, "warn": false, "stdin_add_newline": true, 
"strip_empty_ends": true, "argv": null, "chdir": null, "executable": null, 
"creates": null, "removes": null, "stdin": null}}}\r\n', b'Shared connection to 
rhel8-vm.local closed.\r\n')
<rhel8-vm.local> Failed to connect to the host via ssh: Shared connection to 
rhel8-vm.local closed.
<rhel8-vm.local> ESTABLISH SSH CONNECTION FOR USER: None
<rhel8-vm.local> 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 ConnectTimeout=10 -o 
'ControlPath="/home/gwagner/.ansible/cp/e2fa0cd750"' rhel8-vm.local '/bin/sh -c 
'"'"'rm -f -r /var/tmp/ansible-tmp-1659080275.14459-73519-46884224045778/ > 
/dev/null 2>&1 && sleep 0'"'"''
<rhel8-vm.local> (0, b'', b'')
fatal: [rhel8-vm.local]: FAILED! => {
    "changed": true,
    "cmd": [
        "mv",
        "{'changed': False, 'stat': {'exists': True, 'path': 
'/opt/db/data/postgres/data', 'mode': '0750', 'isdir': True, 'ischr': False, 
'isblk': False, 'isreg': False, 'isfifo': False, 'islnk': False, 'issock': 
False, 'uid': 1001, 'gid': 1001, 'size': 4096, 'inode': 65664, 'dev': 64779, 
'nlink': 20, 'atime': 1659080065.949395, 'mtime': 1659017614.6222425, 'ctime': 
1659080076.9242337, 'wusr': True, 'rusr': True, 'xusr': True, 'wgrp': False, 
'rgrp': True, 'xgrp': True, 'woth': False, 'roth': False, 'xoth': False, 
'isuid': False, 'isgid': False, 'blocks': 8, 'block_size': 4096, 'device_type': 
0, 'readable': False, 'writeable': False, 'executable': False, 'pw_name': 
'postgres', 'gr_name': 'postgres', 'mimetype': 'inode/directory', 'charset': 
'binary', 'version': None, 'attributes': [], 'attr_flags': ''}, 'failed': 
False}",
        "/opt/db/data/postgres/data_legacy"
    ],
    "delta": "0:00:00.004034",
    "end": "2022-07-29 09:37:55.635130",
    "invocation": {
        "module_args": {
            "_raw_params": "mv \"{'changed': False, 'stat': {'exists': True, 
'path': '/opt/db/data/postgres/data', 'mode': '0750', 'isdir': True, 'ischr': 
False, 'isblk': False, 'isreg': False, 'isfifo': False, 'islnk': False, 
'issock': False, 'uid': 1001, 'gid': 1001, 'size': 4096, 'inode': 65664, 'dev': 
64779, 'nlink': 20, 'atime': 1659080065.949395, 'mtime': 1659017614.6222425, 
'ctime': 1659080076.9242337, 'wusr': True, 'rusr': True, 'xusr': True, 'wgrp': 
False, 'rgrp': True, 'xgrp': True, 'woth': False, 'roth': False, 'xoth': False, 
'isuid': False, 'isgid': False, 'blocks': 8, 'block_size': 4096, 'device_type': 
0, 'readable': False, 'writeable': False, 'executable': False, 'pw_name': 
'postgres', 'gr_name': 'postgres', 'mimetype': 'inode/directory', 'charset': 
'binary', 'version': None, 'attributes': [], 'attr_flags': ''}, 'failed': 
False}\" \"/opt/db/data/postgres/data_legacy\"",
            "_uses_shell": false,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": false
        }
    },
    "msg": "non-zero return code",
    "rc": 1,
    "start": "2022-07-29 09:37:55.631096",
    "stderr": "mv: cannot stat '{'\\''changed'\\'': False, '\\''stat'\\'': 
{'\\''exists'\\'': True, '\\''path'\\'': '\\''/opt/db/data/postgres/data'\\'', 
'\\''mode'\\'': '\\''0750'\\'', '\\''isdir'\\'': True, '\\''ischr'\\'': False, 
'\\''isblk'\\'': False, '\\''isreg'\\'': False, '\\''isfifo'\\'': False, 
'\\''islnk'\\'': False, '\\''issock'\\'': False, '\\''uid'\\'': 1001, 
'\\''gid'\\'': 1001, '\\''size'\\'': 4096, '\\''inode'\\'': 65664, 
'\\''dev'\\'': 64779, '\\''nlink'\\'': 20, '\\''atime'\\'': 1659080065.949395, 
'\\''mtime'\\'': 1659017614.6222425, '\\''ctime'\\'': 1659080076.9242337, 
'\\''wusr'\\'': True, '\\''rusr'\\'': True, '\\''xusr'\\'': True, 
'\\''wgrp'\\'': False, '\\''rgrp'\\'': True, '\\''xgrp'\\'': True, 
'\\''woth'\\'': False, '\\''roth'\\'': False, '\\''xoth'\\'': False, 
'\\''isuid'\\'': False, '\\''isgid'\\'': False, '\\''blocks'\\'': 8, 
'\\''block_size'\\'': 4096, '\\''device_type'\\'': 0, '\\''readable'\\'': 
False, '\\''writeable'\\'': False, '\\''executable'\\'': 
 False, '\\''pw_name'\\'': '\\''postgres'\\'', '\\''gr_name'\\'': 
'\\''postgres'\\'', '\\''mimetype'\\'': '\\''inode/directory'\\'', 
'\\''charset'\\'': '\\''binary'\\'', '\\''version'\\'': None, 
'\\''attributes'\\'': [], '\\''attr_flags'\\'': '\\'''\\''}, '\\''failed'\\'': 
False}': No such file or directory",
    "stderr_lines": [
        "mv: cannot stat '{'\\''changed'\\'': False, '\\''stat'\\'': 
{'\\''exists'\\'': True, '\\''path'\\'': '\\''/opt/db/data/postgres/data'\\'', 
'\\''mode'\\'': '\\''0750'\\'', '\\''isdir'\\'': True, '\\''ischr'\\'': False, 
'\\''isblk'\\'': False, '\\''isreg'\\'': False, '\\''isfifo'\\'': False, 
'\\''islnk'\\'': False, '\\''issock'\\'': False, '\\''uid'\\'': 1001, 
'\\''gid'\\'': 1001, '\\''size'\\'': 4096, '\\''inode'\\'': 65664, 
'\\''dev'\\'': 64779, '\\''nlink'\\'': 20, '\\''atime'\\'': 1659080065.949395, 
'\\''mtime'\\'': 1659017614.6222425, '\\''ctime'\\'': 1659080076.9242337, 
'\\''wusr'\\'': True, '\\''rusr'\\'': True, '\\''xusr'\\'': True, 
'\\''wgrp'\\'': False, '\\''rgrp'\\'': True, '\\''xgrp'\\'': True, 
'\\''woth'\\'': False, '\\''roth'\\'': False, '\\''xoth'\\'': False, 
'\\''isuid'\\'': False, '\\''isgid'\\'': False, '\\''blocks'\\'': 8, 
'\\''block_size'\\'': 4096, '\\''device_type'\\'': 0, '\\''readable'\\'': 
False, '\\''writeable'\\'': False, '\\''executable'\\'': False,
  '\\''pw_name'\\'': '\\''postgres'\\'', '\\''gr_name'\\'': '\\''postgres'\\'', 
'\\''mimetype'\\'': '\\''inode/directory'\\'', '\\''charset'\\'': 
'\\''binary'\\'', '\\''version'\\'': None, '\\''attributes'\\'': [], 
'\\''attr_flags'\\'': '\\'''\\''}, '\\''failed'\\'': False}': No such file or 
directory"
    ],
    "stdout": "",
    "stdout_lines": []
}

PLAY RECAP 
************************************************************************************************************************
rhel8-vm.local : ok=2    changed=0    unreachable=0    failed=1    skipped=0    
rescued=0    ignored=0   
localhost                  : ok=1    changed=0    unreachable=0    failed=0    
skipped=0    rescued=0    ignored=0

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1441951566.514067.1659085776589%40office.mailbox.org.

Reply via email to