contents of playbook: install_zip.yml
---
- name: install applications from a zip
hosts: all
roles:
- install_zip
contents of roles/install_zip/vars/main.yml
pt_dir: 'c:\temp-ansible'
jdk_ver: '1.8.0_131'
jdk_file: "jdk-{{ jdk_ver }}.zip"
zip_info:
- { basedir: "{{ pt_dir }}", abspath: "{{ pt_dir }}\\{{ jdk_file }}", dstpath: "c:\\java\\{{ jdk_ver }}", srcurl: "{{ jdk_baseurl }}/{{ jdk_ver }}/{{ jdk_file}}" }
contents of roles/install_zip/tasks/main.yml
---
- name: create base directory
ansible.windows.win_file:
path: "{{ item.basedir }}"
state: directory
with_items: "{{ zip_info }}"
when: ( ansible_os_family == "Windows" )
- name: download zip
ansible.windows.win_get_url:
url: "{{ item.srcurl }}"
dest: "{{ item.abspath }}"
with_items: "{{ zip_info }}"
when: ( ansible_os_family == "Windows" )
- name: check if directory exists
win_stat:
path: "{{ item.dstpath }}"
with_items: "{{ zip_info }}"
register: dir_stat
when: ( ansible_os_family == "Windows" )
- name: print variable
debug:
msg: "{{ dir_stat }}"
when: ( ansible_os_family == "Windows" )
- name: decompress zip
win_unzip:
dest: "{{ item.dstpath }}"
src: "{{ item.abspath }}"
with_items: "{{ zip_info }}"
when: ( ansible_os_family == "Windows" )
here is my output
PLAY [install applications from a zip] ****************************************************************************
TASK [Gathering Facts] ********************************************************************************************
ok: [10.1.1.1]
TASK [install_zip : create base directory] ************************************************************************
TASK [install_zip : download zip] *********************************************************************************
TASK [install_zip : check if directory exists] ********************************************************************
TASK [install_zip : print variable] *******************************************************************************
ok: [10.1.1.1] =>
msg:
changed: false
msg: All items completed
results:
- ansible_loop_var: item
changed: false
failed: false
invocation:
module_args:
checksum_algorithm: sha1
follow: false
get_checksum: true
path: c:\java\1.8.0_131
item:
abspath: c:\temp-ansible\jdk-1.8.0_131.zip
basedir: c:\temp-ansible
dstpath: c:\java\1.8.0_131
stat:
attributes: Directory
creationtime: 1619713791.4490106
exists: true
filename: 1.8.0_131
hlnk_targets: []
isarchive: false
isdir: true
ishidden: false
isjunction: false
islnk: false
isreadonly: false
isreg: false
isshared: false
lastaccesstime: 1619713791.5422983
lastwritetime: 1619713791.5422983
nlink: 1
owner: BUILTIN\Administrators
path: c:\java\1.8.0_131
size: 372169148
skipping: [Dev0015248]
PLAY RECAP ********************************************************************************************************
10.1.1.1 : ok=5 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0