forked from Ludovic-Menard/ansible-for-i-usecases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ibmi_try_tower_structure.yml
79 lines (64 loc) · 2.16 KB
/
ibmi_try_tower_structure.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
# The playbook is to demostrate leverage IBM i modules and plugins in Ansible tower.
- hosts: all
gather_facts: no
collections:
- ibm.power_ibmi
vars:
#Required parameters
lib_name: "TOWERLIB"
savf_name: "TOWERSAVF"
tasks:
- block:
- name: Create library
ibmi_cl_command:
cmd: CRTLIB LIB({{lib_name}})
- name: Create savf
ibmi_cl_command:
cmd: CRTSAVF FILE({{lib_name}}/{{savf_name}})
- name: find the created savf object
ibmi_object_find:
lib_name: "{{lib_name}}"
object_name: "{{savf_name}}"
register: find_result
- name: assert 1 object was found
assert:
that:
- find_result.object_list | length == 1
- name: Show found object returned by ibmi_object_find module.
debug: var=find_result verbosity=0
- name: Create a local temporary directory
shell: mktemp -d /tmp/ansible_test.XXXXXXXXX
register: tempfile_result
delegate_to: localhost
notify: 'remove the created temp folder'
- set_fact:
local_temp_dir: '{{ tempfile_result.stdout }}'
- name: Fetch the savf to local
ibmi_fetch:
object_names: '{{savf_name}}'
lib_name: '{{lib_name}}'
object_types: '*FILE'
dest: '{{local_temp_dir}}'
register: fetch_result
- name: Show fetch result returned by ibmi_fetch module.
debug: var=fetch_result verbosity=0
- name: Show the fetched file state
stat:
path: '{{local_temp_dir}}/{{ inventory_hostname }}/QSYS.LIB/{{lib_name.upper()}}.LIB/{{savf_name}}.FILE'
delegate_to: localhost
register: fetched_file_state
- name: Show fetched object returned by stat module.
debug: var=fetched_file_state verbosity=0
always:
- name: remove the created library
ibmi_cl_command:
cmd: DLTLIB LIB({{lib_name}})
ignore_errors: true
handlers:
- name: remove the created temp folder
file:
state: absent
path: '{{local_temp_dir}}'
delegate_to: localhost
ignore_errors: true