Ansible role to provision a zone on OpenIndiana
Olaf Bohlen
2020-08-25 a9c6b8a0d39219fe12790c3e33ca8646b865e676
commit | author | age
9cdfbb 1 ---
3ada41 2 # tasks file for oi-zone
4b5fae 3 - name: creating zone for you
OB 4   block:
e7b69f 5     # jump into rescue if we want to uninstall
OB 6     - name: check for uninstall
7       fail:
8         msg: "uninstall is set to true, deleting resources"
9       when:
10         - oizone['uninstall'] is defined
11         - oizone['uninstall']
12         
4b5fae 13     - name: create VNICs with VLAN
OB 14       dladm_vnic:
15         name: "{{ item['logical'] }}"
16         link: "{{ item['physical'] }}"
17         vlan: "{{ item['vlan'] }}"
18       loop: "{{ oizone['nics'] }}"
19       when: item['vlan'] is defined
3ada41 20
4b5fae 21     - name: create VNICs without VLAN
OB 22       dladm_vnic:
23         name: "{{ item['logical'] }}"
24         link: "{{ item['physical'] }}"
25       loop: "{{ oizone['nics'] }}"
26       when: item['vlan'] is not defined
27
28     - name: create filesystems
29       zfs:
30         name: "{{ item['path'] }}"
31         state: present
32         extra_zfs_properties: "{{ item['extra_zfs_properties'] }}"
33       loop: "{{ oizone['filesystems'] }}"
34       when: item['zfscreate']
a9c6b8 35
OB 36     - name: is the zone already there?
37       shell: zoneadm -z {{ oizone['name'] }} list
38       register: zoneout
39       changed_when: false
40       ignore_errors: true
41       
4b5fae 42     - name: set up VM zones for master
OB 43       solaris_zone:
44         name: "{{ oizone['name'] }}"
45         state: installed
46         path: "{{ oizone['zoneroot'] }}/{{ oizone['name'] }}"
a9c6b8 47         install_options: "-e pkg:/security/sudo -e runtime/python-27"
4b5fae 48         config: >
OB 49           set brand={{ oizone['brand'] }};
50           set autoboot={{ oizone['autoboot'] }};
51           {% if oizone['bootargs'] is defined and oizone['bootargs'] | length %}
52           set bootargs={{ oizone['bootargs'] }};
53           {% endif %}
54           set ip-type={{ oizone['iptype'] }};
55           {% for nic in oizone['nics'] %}
56           add net;
57           set physical={{ nic['logical'] }};
58           {% if oizone['iptype'] == "shared" %}
59           set address={{ nic['address'] }};
60           {% endif %}
61           end;
62           {% endfor %}
63           {% if oizone['cpus'] is defined and oizone['cpus'] == "dedicated" %}
64           add dedicated-cpu;
65           set ncpus={{ oizone['ncpus'] }};
66           end;
67           {% endif %}
68           {% if oizone['cpus'] is defined and oizone['cpus'] == "capped-cpu" %}
69           add capped-cpu;
70           set ncpus={{ oizone['ncpus'] }};
71           end;
72           {% endif %}
73           {% if oizone['mem'] is defined and oizone['mem'] == "capped-memory" %}
74           add capped-memory;
75           set physical={{ oizone['ram'] }};
76           set swap={{ oizone['swap'] }};
77           set locked={{ oizone['locked'] }};
78           end;
79           {% endif %}
80           {% for dataset in oizone['filesystems'] %}
81           {% if dataset['type'] == "dataset" %}
82           add dataset;
83           set name={{ dataset['path'] }};
84           end;
85           {% endif %}
86           {% if dataset['type'] == "lofs" %}
87           add fs;
88           set special={{ dataset['path'] }};
89           set dir={{ dataset['mountpoint'] }};
90           set type="lofs";
91           {% for option in database['options'] %}
92           add options {{ option }};
93           {% endfor %}
94           end;
95           {% endif %}
96           {% if dataset['type'] == "volume" %}
97           add device;
98           set match=/dev/zvol/rdsk/{{ dataset['path'] }};
99           end;
100           {% endif %}
101           {% endfor %}
102           {% if oizone['brand'] == "kvm" %}
103           add attr;
104           set name="bootorder";
105           set type="string";
106           set value="{{ oizone['kvm']['bootorder'] }}";
107           add attr;
108           set name="vnc";
109           set type="string";
110           set value="{{ oizone['kvm']['vnc'] }}";
111           end;
112           add attr;
113           set name="vcpus";
114           set type="string";
115           set value="{{ oizone['ncpus'] }}";
116           end;
117           add attr;
118           set name="ram";
119           set type="string";
120           set value="{{ oizone['ram'] }}";
121           end;
122           {% endif %}
a9c6b8 123       when: zoneout.rc == 1
OB 124       
4b5fae 125     - name: create a sysding.conf
OB 126       template:
127         dest: "{{ oizone['zoneroot'] }}/{{ oizone['name'] }}/root/etc/sysding.conf"
128         src: sysding.j2
129         mode: 0400
130
131     - name: boot zone
132       solaris_zone:
133         name: "{{ oizone['name'] }}"
134         state: running
135         path: "{{ oizone['zoneroot'] }}/{{ oizone['name'] }}"
136
137     - name: add zone to inventory
138       local_action:
139         module: lineinfile
140         path: "{{ inventory_file }}"
141         insertbefore: "BOF"
142         line: "{{ oizone['name'] }}.{{ oizone['sysding']['ip']['dns']['domain'] }}"
143       when:
144         - oizone['updateinventory'] is defined
145         - oizone['updateinventory']
146       
147   rescue:   # in case something wents wrong above, we do housekeeping here
148     - name: ATTENTION
149       debug:
150         msg: "failed to install {{ oizone['name'] }}, rolling back"
151     - name: delete zone
152       solaris_zone:
153         name: "{{ oizone['name'] }}"
154         state: absent
155         path: "{{ oizone['zoneroot'] }}/{{ oizone['name'] }}"
156
157     - name: delete VNICs
158       dladm_vnic:
159         name: "{{ item['logical'] }}"
160         link: "{{ item['physical'] }}"
161         state: absent
162       loop: "{{ oizone['nics'] }}"
163         
164     - name: delete filesystems
165       zfs:
166         name: "{{ item['path'] }}"
167         state: absent
168         extra_zfs_properties: "{{ item['extra_zfs_properties'] }}"
169       loop: "{{ oizone['filesystems'] }}"
170       when: item['zfscreate']
171