renaming a folder on the remote ... issue with defaults/main.yml

256 views
Skip to first unread message

dulh...@mailbox.org

unread,
Jul 29, 2022, 5:09:54 AM7/29/22
to ansible...@googlegroups.com
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

Dick Visser

unread,
Jul 29, 2022, 5:25:02 AM7/29/22
to ansible...@googlegroups.com
On Fri, 29 Jul 2022 at 11:09, dulhaver via Ansible Project
<ansible...@googlegroups.com> wrote:

> "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"

You are trying to move a directory called '{'\\''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}', which does not exist.

The variable you register with stat is not just a string, but a dict.
You should use the correct key from that dict (i.e. 'postgres_data.path')

Dick Visser

unread,
Jul 29, 2022, 5:26:02 AM7/29/22
to ansible...@googlegroups.com
On Fri, 29 Jul 2022 at 11:24, Dick Visser <dnmv...@gmail.com> wrote:

> You should use the correct key from that dict (i.e. 'postgres_data.path')

probably 'postgres_data.stat.path'

dulh...@mailbox.org

unread,
Jul 29, 2022, 6:02:20 AM7/29/22
to ansible...@googlegroups.com
it seems neither

´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´
- 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.path
become: true
´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´
nor

´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´
- 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.path
become: true
´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´

seems to make any difference. When I put harcoded locations the dir is renamed, when I use the variables from the defaults/main.yml it isn't

Dick Visser

unread,
Jul 29, 2022, 6:24:46 AM7/29/22
to ansible...@googlegroups.com
Correct.
I assumed it was obvious that my suggestion was for the variable in
the command - because that is what the error is about.
You used it in the 'when' clause - which does not make sense as that
was OK to start with.
But now I see another issue with your code. You use 'postgres_data' as
a variable in the stat task, which you then overwrite with the results
of that task.
That is very confusing and the source of your error.
Rather than describing things and then running the risk of
misinterpretation again, perhaps it's better to just spell it out
entirely:




- name: move legacy postgres - stat postgres_data
stat: path="{{ postgres_data }}"
register: pgdatastat

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

dulh...@mailbox.org

unread,
Jul 29, 2022, 11:05:56 AM7/29/22
to ansible...@googlegroups.com
that works now, thx.

Apparently I still will have to study what 'stat' acutally does under the hood before I really get what actually happens here and why.
Reply all
Reply to author
Forward
0 new messages