On Tue, 27 Nov 2018 at 09:52, visar <
vivu...@gmail.com> wrote:
>
> Hi Experts,
>
> I have below play book for extracting a .zip file from Ansible controller machine to the target folders. But i noticed that play is not working as expected if the target folder and the unzipped files are already present in the target servers. Could you please guide me here ?
Hi
Some questions:
1. The playbook is restricted to localhost, and 'extracting a .zip
file from Ansible controller machine to the target folders' also
indicates you want to extract a ZIP file on the controller machine.
But then your talk about 'files are already present in the target
servers' - which indicates that you DO want to extract the archive on
a remote host. What do you actually mean?
2. You mention that the play 'is not working as expected'. The
question then is: what _did_ you expect (and what exactly isn't going
as you expected)?
3. You now use a fragile combination of two modules (stat + command)
to achieve what can also be done with only one module: file.
4. The 'creates' parameter of the unarchive module should be an
absolute path, but you specify it as 'no'.
5. Cosmetically: you define 'source_dir' but then the value is the
path of a (ZIP) file. Strictly speaking there is nothing wrong, but it
does make things confusing.
6. If this is part of a role (which
'/etc/ansible/roles/IBM2/files/mypack.zip' indicates), you could leave
out the full path as this will be implicit (i.e. just
'files/mypack.zip')
The good news is that, depending on what you really want (still
unclear at this point), it could be as simple as use a single
unarchive task.
At the risk of guessing:
- name: Extract file
hosts: targethosts
vars:
zipfile: files/mypack.zip
destdir: /opt/mypack
tasks:
- name: extract zip file
unarchive:
src: "{{ zipfile }}"
dest: "{{ destdir }}"
Dick
>
> ############################################################
>
> ---
>
> - name: Extract mypack.zip into /opt/mypack
> hosts: localhost
> vars:
> source_dir: /etc/ansible/roles/IBM2/files/mypack.zip
> dest_dir: /opt/mypack
> tasks:
> - name: check the folder existance
> stat: path=/opt/mypack
> register: folder_exist
>
> - name: create directory
> command: mkdir /opt/mypack
> when: folder_exist.stat.exists == False
>
> - name: extract the .zip file
> unarchive:
> src: "{{ source_dir }}"
> dest: "{{ dest_dir }}/"
> creates: no
> when: folder_exist.stat.exists == True
>
> #####################################################################
>
> --
> 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.
> To post to this group, send email to
ansible...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/09e072d7-a3f6-485a-8e9b-fb8d8497228b%40googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.