On 1/18/21 6:18 PM, Gerard Weatherby wrote:
> Just use shell and copy:
>
> - hosts: all
>
> become: true
>
> tasks:
>
> - name: backup name
>
> set_fact:
>
> tdate: "bkp.{{ '%d%b%Y_%H%M%S' | strftime }}"
>
> - name: Take Backup when dest_path and source path are the same.
>
> shell: cp -ar /tmp/x "/tmp/x.{{ tdate }}"
>
>
There is no sane reason to use the shell module. This will work with the command module
as well.
Regards
Racke
> On Monday, January 18, 2021 at 12:46:58 AM UTC-5
shif...@gmail.com wrote:
>
> The actual folder had 777 permissions as seen below:
>
> drwxrwxrwx 3 destuser destuser 29 Jan 14 08:40 /tmp/mohtas/folder
> **//___^
> I took the backup using the below playbook and wanted to preserve the permissions i.e 777 for the backup folder
> `/tmp/mohtas/folder.bkp.15Jan2021_090700`
> **//___^
> ---
> - name: "Play 3"
> hosts: all
> user: destuser
> tasks:
> - set_fact:
> tdate: "bkp.{{ '%d%b%Y_%H%M%S' | strftime }}"
>
> - name: Take Backup when dest_path and source path are the same.
> ignore_errors: yes
> copy:
> src: "/tmp/mohtas/folder"
> dest: "/tmp/mohtas/folder.{{ tdate }}"
> mode: preserve
> **//___^
>
> However, the backup folder was created with a different permissions as below:
>
> drwxr-xr-x 3 destuser destuser 17 Jan 15 09:07 /tmp/mohtas/folder.bkp.15Jan2021_090700
>
> I understand that I can use statmodule but was looking for a better/quicker solution as i'm dealing with a loop of
> files/folders.
> **//___^
> My ansible version is:
> [destuser@desthost /]$ ansible --version ansible 2.4.2.0 config file = /home/destuser/.ansible.cfg configured module
> search path = [u'/home/destuser/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python
> module location = /usr/lib/python2.7/site-packages/ansible executable location = /bin/ansible python version = 2.7.5
> **//___^
> Note: The strange thing is the backup permissions are preserved if i mention
> src: /tmp/mohtas/file.txtas a file and not a directory.
> **//___^**//___^**//___^**//___^**//___^
>
> --
> 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-proje...@googlegroups.com <mailto:
ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/ansible-project/b857c2f2-cf3c-4295-95b4-97442dad7d6an%40googlegroups.com
> <
https://groups.google.com/d/msgid/ansible-project/b857c2f2-cf3c-4295-95b4-97442dad7d6an%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.