On 01/11/2022 18:42, Kenady Inampudi wrote:
even with loop: "{{ users }}"  there is no difference

I think you need to loop over {{ user }} and in path/dest use {{ item }}, the 
default loop variable.

Regards

        Racke


archive_home_dir.yml
---
- hosts: all
  tasks:
     - archive:
          path: /home/{{ user }}
          dest: /home/archive/{{ user }}.tar.gz
          format: gz
       loop: "{{ users }}"

it still creates
-rw-r--r--    1 root     system           88 Nov 01 13:37 [u'user1', 
u'user2'].tar.gz

ansible-playbook -i test_host archive_home_dir.yml -e @users.yml

PLAY [all] 
********************************************************************************************************************************************************************************************************

TASK [archive] 
****************************************************************************************************************************************************************************************************
changed: [server1] => (item=user1)
ok: [server1] => (item=user2)
changed: [server2] => (item=user1)
ok: [server2] => (item=user2)
changed: [server3] => (item=user1)
ok: [server3] => (item=user2)

PLAY RECAP 
********************************************************************************************************************************************************************************************************
server1               : ok=1    changed=1    unreachable=0  failed=0    
skipped=0    rescued=0    ignored=0
server2                : ok=1    changed=1    unreachable=0  failed=0    
skipped=0    rescued=0    ignored=0
server3                : ok=1    changed=1    unreachable=0  failed=0    
skipped=0    rescued=0    ignored=0

On Tuesday, November 1, 2022 at 10:55:44 PM UTC+5:30 [email protected] wrote:

    Kenady,

    I think you are looking to loop[1] the users correct?

    aka

    loop: "{{ users }}"

    1. https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html



    On Tue, Nov 1, 2022 at 10:31 AM Kenady Inampudi <[email protected]> wrote:

        Archiving user home directories


        user.yml
        ---
        user:
          - user1
          - user2

        archive_home_dir.yml
        ---
        - hosts: all
          tasks:
             - archive:
                  path: /home/{{ user }}
                  dest: /home/archive/{{ user }}.tar.gz
                  format: gz
        ansible-playbook archive_home_dir.yml -e @user.yml

        i get
        -rw-r--r--    1 root     system           88 Nov 01 11:58 [u'user1', 
u'user2'].tar.gz

        i was expecting
        -rw-r--r--    1 root     system           88 Nov 01 11:58 user1.tar.gz
        -rw-r--r--    1 root     system           88 Nov 01 11:58 user2.tar.gz

-- 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/3df53de7-82a5-4430-9146-8c03755f923an%40googlegroups.com
 
<https://groups.google.com/d/msgid/ansible-project/3df53de7-82a5-4430-9146-8c03755f923an%40googlegroups.com?utm_medium=email&utm_source=footer>.



-- - Andrew "lathama" Latham -

--
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/4f42f266-404e-44b8-b851-1d6728d0cd14n%40googlegroups.com
 
<https://groups.google.com/d/msgid/ansible-project/4f42f266-404e-44b8-b851-1d6728d0cd14n%40googlegroups.com?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/6b01fa72-55bb-5931-e227-fca47410aaaa%40linuxia.de.

Reply via email to