Hello Bharath,
Thanks for your suggestion and i tried with below play and it didnt get
succeed.
play
_________
---
- name: extract the packages
hosts: localhost,CCM
gather_facts: no
tasks:
- name: Ensure the folder exists!
file:
path: /opt/mypack1
state: directory
mode: 0755
- name: Unpack/Unarchive the .zip file!
unarchive:
src: "{{ item }}"
dest: /opt/mypack1
remote_src: no
with_items:
- /etc/ansible/roles/IBM2/files/mypack1.zip
- /etc/ansible/roles/IBM2/files/mypack2.zip
error
_____
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an
undefined variable. The error was: 'item' is undefined\n\nThe error appears
to have been in '/etc/ansible/roles/IBM2/tasks/good/unarchive2.yml': line
12, column 7, but may\nbe elsewhere in the file depending on the exact
syntax problem.\n\nThe offending line appears to be:\n\n mode:
0755\n - name: Unpack/Unarchive the .zip file!\n ^ here\n"}
fatal: [10.50.3.1]: FAILED! => {"msg": "The task includes an option with an
undefined variable. The error was: 'item' is undefined\n\nThe error appears
to have been in '/etc/ansible/roles/IBM2/tasks/good/unarchive2.yml': line
12, column 7, but may\nbe elsewhere in the file depending on the exact
syntax problem.\n\nThe offending line appears to be:\n\n mode:
0755\n - name: Unpack/Unarchive the .zip file!\n ^ here\n"}
Note:- here i was trying to unzip my two .zip packages to 2 different
directory (like mypack1.zip to /opt/mypack1 and mypack2.zip to /opt/mypack2)
On Wednesday, November 28, 2018 at 9:23:38 AM UTC+5:30, Bharath Kumar wrote:
>
> Try the below (check for indentation)
>
> ---
> - hosts: all
> gather_facts: no
> tasks:
> - name: Ensure the folder exists!
> file:
> path: /opt/mypack
> state: directory
> mode: 0755
> - name: Unpack/Unarchive the .zip file!
> unarchive:
> src: {{ item }}
> dest: /opt/mypack
> remote_src: no
> with_items:
> - /etc/ansible/roles/IBM2/files/mypack.zip
> - /etc/ansible/roles/IBM2/files/mypack2.zip
>
>
>
>
> On Tuesday, November 27, 2018 at 7:57:23 AM UTC-5, visar wrote:
>
>> Hello Dick,
>>
>> Thanks for all your suggestions.
>>
>> I am very sorry for the mistake in my playbook which i copied here.
>> Actually as i stated i would need to extract the mypack.zip file which is
>> in the controller machine to all my application servers( here by mistake i
>> defined as localhost, where as a list of servers are there).
>>
>> my aim is that extract the .zip file in the controller to the specific
>> folder in application servers (because i have another script with this path
>> specified for calling the package).
>>
>> i was trying for 2 conditions
>>
>> 1) check the target servers directory present or not (eg: /opt/mypack).
>> if it present skip else create directory.
>> 2) check the above directory already have the extracted file or not. if
>> no extract, if yes skip extract.
>>
>>
>>
>> I tried with below playbook where i want to extract 2 .zip packages to
>> all target servers specific location (/opt/mypack and /opt/mypack2)
>>
>>
>> ---
>>
>> - name: Extract CLM-Web Package into /opt/mypack
>> hosts: localhost,IHS,CCM,RM
>> 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 }}/"
>> when: folder_exist.stat.exists == True
>>
>> - name: Extract CLM Installation Package to /opt/mypack
>> hosts: localhost,CCM,RM
>> vars:
>> source_dir: /etc/ansible/roles/IBM2/files/mypack2.zip
>> dest_dir: /opt/mypack2
>> tasks:
>> - name: check the folder existance
>> stat: path=/opt/mypack2
>> register: folder_exist
>>
>> - name: create directory
>> command: mkdir /opt/mypack2
>> when: folder_exist.stat.exists == False
>>
>> - name: extract the .zip file
>> unarchive:
>> src: "{{ source_dir }}"
>> dest: "{{ dest_dir }}/"
>> when: folder_exist.stat.exists == True
>>
>>
>> On Tuesday, November 27, 2018 at 4:58:26 PM UTC+5:30, Dick Visser wrote:
>>>
>>> On Tue, 27 Nov 2018 at 09:52, visar <[email protected]> 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 [email protected].
>>> > To post to this group, send email to [email protected].
>>> > 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.
>>>
>>
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/38bae564-c226-4864-9c4a-99f034c2d9d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.