Ansible role to provision a zone on OpenIndiana
Olaf Bohlen
2020-08-25 e7b69ff4c5a13600b9fc1e20a93ff8fec4237bc7
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']
3ada41 35   
4b5fae 36     - name: set up VM zones for master
OB 37       solaris_zone:
38         name: "{{ oizone['name'] }}"
39         state: installed
40         path: "{{ oizone['zoneroot'] }}/{{ oizone['name'] }}"
e7b69f 41         install_options: "-e pkg:/security/sudo"
4b5fae 42         config: >
OB 43           set brand={{ oizone['brand'] }};
44           set autoboot={{ oizone['autoboot'] }};
45           {% if oizone['bootargs'] is defined and oizone['bootargs'] | length %}
46           set bootargs={{ oizone['bootargs'] }};
47           {% endif %}
48           set ip-type={{ oizone['iptype'] }};
49           {% for nic in oizone['nics'] %}
50           add net;
51           set physical={{ nic['logical'] }};
52           {% if oizone['iptype'] == "shared" %}
53           set address={{ nic['address'] }};
54           {% endif %}
55           end;
56           {% endfor %}
57           {% if oizone['cpus'] is defined and oizone['cpus'] == "dedicated" %}
58           add dedicated-cpu;
59           set ncpus={{ oizone['ncpus'] }};
60           end;
61           {% endif %}
62           {% if oizone['cpus'] is defined and oizone['cpus'] == "capped-cpu" %}
63           add capped-cpu;
64           set ncpus={{ oizone['ncpus'] }};
65           end;
66           {% endif %}
67           {% if oizone['mem'] is defined and oizone['mem'] == "capped-memory" %}
68           add capped-memory;
69           set physical={{ oizone['ram'] }};
70           set swap={{ oizone['swap'] }};
71           set locked={{ oizone['locked'] }};
72           end;
73           {% endif %}
74           {% for dataset in oizone['filesystems'] %}
75           {% if dataset['type'] == "dataset" %}
76           add dataset;
77           set name={{ dataset['path'] }};
78           end;
79           {% endif %}
80           {% if dataset['type'] == "lofs" %}
81           add fs;
82           set special={{ dataset['path'] }};
83           set dir={{ dataset['mountpoint'] }};
84           set type="lofs";
85           {% for option in database['options'] %}
86           add options {{ option }};
87           {% endfor %}
88           end;
89           {% endif %}
90           {% if dataset['type'] == "volume" %}
91           add device;
92           set match=/dev/zvol/rdsk/{{ dataset['path'] }};
93           end;
94           {% endif %}
95           {% endfor %}
96           {% if oizone['brand'] == "kvm" %}
97           add attr;
98           set name="bootorder";
99           set type="string";
100           set value="{{ oizone['kvm']['bootorder'] }}";
101           add attr;
102           set name="vnc";
103           set type="string";
104           set value="{{ oizone['kvm']['vnc'] }}";
105           end;
106           add attr;
107           set name="vcpus";
108           set type="string";
109           set value="{{ oizone['ncpus'] }}";
110           end;
111           add attr;
112           set name="ram";
113           set type="string";
114           set value="{{ oizone['ram'] }}";
115           end;
116           {% endif %}
3ada41 117
4b5fae 118     - name: create a sysding.conf
OB 119       template:
120         dest: "{{ oizone['zoneroot'] }}/{{ oizone['name'] }}/root/etc/sysding.conf"
121         src: sysding.j2
122         mode: 0400
123
124     - name: boot zone
125       solaris_zone:
126         name: "{{ oizone['name'] }}"
127         state: running
128         path: "{{ oizone['zoneroot'] }}/{{ oizone['name'] }}"
129
130     - name: add zone to inventory
131       local_action:
132         module: lineinfile
133         path: "{{ inventory_file }}"
134         insertbefore: "BOF"
135         line: "{{ oizone['name'] }}.{{ oizone['sysding']['ip']['dns']['domain'] }}"
136       when:
137         - oizone['updateinventory'] is defined
138         - oizone['updateinventory']
139       
140   rescue:   # in case something wents wrong above, we do housekeeping here
141     - name: ATTENTION
142       debug:
143         msg: "failed to install {{ oizone['name'] }}, rolling back"
144     - name: delete zone
145       solaris_zone:
146         name: "{{ oizone['name'] }}"
147         state: absent
148         path: "{{ oizone['zoneroot'] }}/{{ oizone['name'] }}"
149
150     - name: delete VNICs
151       dladm_vnic:
152         name: "{{ item['logical'] }}"
153         link: "{{ item['physical'] }}"
154         state: absent
155       loop: "{{ oizone['nics'] }}"
156         
157     - name: delete filesystems
158       zfs:
159         name: "{{ item['path'] }}"
160         state: absent
161         extra_zfs_properties: "{{ item['extra_zfs_properties'] }}"
162       loop: "{{ oizone['filesystems'] }}"
163       when: item['zfscreate']
164