On 27/07/2022 10:33, dulhaver via Ansible Project wrote:
I am trying to rename/move a folder on a remote host and try to do this based 
on whether it exists

That doesn't look like a proper path: "path": " /opt/db/backup/postgres/backups 
".

Also it doesn't coincide with your playbook.

Regards

        Racke


2 TASKS should be doing this
################################################################################
- name: move legacy postgres - stat postgres_base
  stat: path=/opt/db/postgres
  register: postgres_base_stat
- name: move legacy postgres - move postgres_base to postgres_base_legacy
    command: mv /opt/db/postgres /opt/db/postgres/legacy"
    when: postgres_base_stat.stat.exists
################################################################################
The TASKS run through, but do not move the folder as intended, apparently because the stat TASK 
does not return the right value ("skip_reason": "Conditional result was False")
Do I have to reverse the when clause?
below the detailed output
TASK [postgres_disable : move legacy postgres - stat "postgres_back"] 
*******************************************************
task path: 
/home/gwagner/repos/ansible/open_source/postgres_upgrade/roles/postgres_disable/tasks/main.yml:32
<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/8ca9f05e1f"' 
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/8ca9f05e1f"' rhel8-vm.local '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /home/gwagner/.ansible/tmp 
`"&& mkdir "` echo /home/gwagner/.ansible/tmp/ansible-tmp-1658907975.2889578-62723-197073820787608 `" && echo 
ansible-tmp-1658907975.2889578-62723-197073820787608="` echo /home/gwagner/.ansible/tmp/ansible-tmp-1658907975.2889578-62723-197073820787608 `" ) && sleep 
0'"'"''
<rhel8-vm.local> (0, 
b'ansible-tmp-1658907975.2889578-62723-197073820787608=/home/gwagner/.ansible/tmp/ansible-tmp-1658907975.2889578-62723-197073820787608\n',
 b'')
Using module file /usr/lib/python3.8/site-packages/ansible/modules/stat.py
<rhel8-vm.local> PUT 
/home/gwagner/.ansible/tmp/ansible-local-626726_zsgrbg/tmpxz0n4329 TO 
/home/gwagner/.ansible/tmp/ansible-tmp-1658907975.2889578-62723-197073820787608/AnsiballZ_stat.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/8ca9f05e1f"' '[rhel8-vm.local]'
<rhel8-vm.local> (0, b'sftp> put 
/home/gwagner/.ansible/tmp/ansible-local-626726_zsgrbg/tmpxz0n4329 
/home/gwagner/.ansible/tmp/ansible-tmp-1658907975.2889578-62723-197073820787608/AnsiballZ_stat.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/8ca9f05e1f"' 
rhel8-vm.local '/bin/sh -c '"'"'chmod u+x 
/home/gwagner/.ansible/tmp/ansible-tmp-1658907975.2889578-62723-197073820787608/ 
/home/gwagner/.ansible/tmp/ansible-tmp-1658907975.2889578-62723-197073820787608/AnsiballZ_stat.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/8ca9f05e1f"' -tt 
rhel8-vm.local '/bin/sh -c '"'"'/usr/libexec/platform-python 
/home/gwagner/.ansible/tmp/ansible-tmp-1658907975.2889578-62723-197073820787608/AnsiballZ_stat.py && sleep 
0'"'"''
<rhel8-vm.local> (0, b'\r\n{"changed": false, "stat": {"exists": false}, "invocation": {"module_args": {"path": " /opt/db/backup/postgres/backups ", 
"follow": false, "get_md5": false, "get_checksum": true, "get_mime": true, "get_attributes": true, "checksum_algorithm": "sha1"}}}\r\n', b'Shared 
connection to rhel8-vm.local closed.\r\n')
<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/8ca9f05e1f"' rhel8-vm.local 
'/bin/sh -c '"'"'rm -f -r /home/gwagner/.ansible/tmp/ansible-tmp-1658907975.2889578-62723-197073820787608/ > /dev/null 
2>&1 && sleep 0'"'"''
<rhel8-vm.local> (0, b'', b'')
ok: [rhel8-vm.local] => {
"changed": false,
"invocation": {
"module_args": {
"checksum_algorithm": "sha1",
"follow": false,
"get_attributes": true,
"get_checksum": true,
"get_md5": false,
"get_mime": true,
"path": " /opt/db/backup/postgres/backups "
}
},
"stat": {
"exists": false
}
}
Perform task: TASK: postgres_disable : move legacy postgres - rename "postgres_back" to 
"postgre_back/legacy" (N)o/(y)es/(c)ontinue: y
Perform task: TASK: postgres_disable : move legacy postgres - rename "postgres_back" to 
"postgre_back/legacy" (N)o/(y)es/(c)ontinue: ****************************
TASK [postgres_disable : move legacy postgres - rename "postgres_back" to 
"postgre_back/legacy"] ****************************
task path: 
/home/gwagner/repos/ansible/open_source/postgres_upgrade/roles/postgres_disable/tasks/main.yml:35
skipping: [rhel8-vm.local] => {
"changed": false,
"skip_reason": "Conditional result was False"
--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1083094168.383085.1658910834565%40office.mailbox.org
 
<https://groups.google.com/d/msgid/ansible-project/1083094168.383085.1658910834565%40office.mailbox.org?utm_medium=email&utm_source=footer>.


--
Automation expert - Ansible and friends
Linux administrator & Debian maintainer
Perl Dancer & conference hopper

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/03a40a3c-45c5-fc9b-0170-f95ff35c5816%40linuxia.de.

Reply via email to