Re: [ansible-project] renaming a folder on the remote ... issue with defaults/main.yml

2022-07-29 Thread dulhaver via Ansible Project

> On 07/29/2022 12:24 PM CEST Dick Visser  wrote:
> 
>  
> On Fri, 29 Jul 2022 at 12:02, dulhaver via Ansible Project
>  wrote:
> 
> > 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
> 
> 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
> 

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.

-- 
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/1864000443.146.1659107140531%40office.mailbox.org.


Re: [ansible-project] renaming a folder on the remote ... issue with defaults/main.yml

2022-07-29 Thread Dick Visser
On Fri, 29 Jul 2022 at 12:02, dulhaver via Ansible Project
 wrote:

> 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

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

-- 
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/CAF8BbLZKJeaPT1nYFe1LBAF%2BDFHkkAC1AZt902gXFdJPWOXetA%40mail.gmail.com.


Re: [ansible-project] renaming a folder on the remote ... issue with defaults/main.yml

2022-07-29 Thread dulhaver via Ansible Project
> On 07/29/2022 11:24 AM CEST Dick Visser  wrote:
> 
>  
> On Fri, 29 Jul 2022 at 11:09, dulhaver via Ansible Project
>  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')
> 
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

-- 
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/659960991.517578.1659088923524%40office.mailbox.org.


Re: [ansible-project] renaming a folder on the remote ... issue with defaults/main.yml

2022-07-29 Thread Dick Visser
On Fri, 29 Jul 2022 at 11:24, Dick Visser  wrote:

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

probably 'postgres_data.stat.path'

-- 
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/CAF8BbLbbgx3anOoZO7eYJ5ODXK9Y%3Dc6pvL9-pW0zqhV6BXZzDg%40mail.gmail.com.


Re: [ansible-project] renaming a folder on the remote ... issue with defaults/main.yml

2022-07-29 Thread Dick Visser
On Fri, 29 Jul 2022 at 11:09, dulhaver via Ansible Project
 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')

-- 
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/CAF8BbLad-NSKU31KFeH3%2BtKWVE0RKkCsLXX_t0KgAcrxUrvfqQ%40mail.gmail.com.


[ansible-project] renaming a folder on the remote ... issue with defaults/main.yml

2022-07-29 Thread dulhaver via Ansible Project
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
 ESTABLISH SSH CONNECTION FOR USER: None
 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'"'"''
 (0, b'/home/gwagner\n', b'')
 ESTABLISH SSH CONNECTION FOR USER: None
 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'"'"''
 (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
 PUT 
/home/gwagner/.ansible/tmp/ansible-local-73486ma2inx7k/tmpiwfg83t2 TO 
/var/tmp/ansible-tmp-1659080275.14459-73519-46884224045778/AnsiballZ_command.py
 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]'
 (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'')
 ESTABLISH SSH CONNECTION FOR USER: None
 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'"'"''
 (0, b'', b'')
 ESTABLISH SSH CONNECTION FOR USER: None
 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
 (1, b'\r\n{"changed": true, "stdout": "", "stderr": "mv: 
cannot stat \'{\'\'\'changed\'\'\': False, \'\'\'stat\'\'\': 
{\'\'\'exists\'\'\': True, \'\'\'path\'\'\': 
\'\'\'/opt/db/data/postgres/data\'\'\', \'\'\'mode\'\'\': 
\'\'\