From 3ada41b2e02817175192ac3e44f261ee76993a66 Mon Sep 17 00:00:00 2001 From: Olaf Bohlen <olaf.bohlen@niit.com> Date: Wed, 19 Aug 2020 17:54:11 +0200 Subject: [PATCH] initial work --- tasks/main.yml | 112 +++++++++++++++++++++++++++ templates/sysding.j2 | 27 ++++++ defaults/main.yml | 72 +++++++++++++++++ meta/main.yml | 21 +++-- README.md | 2 5 files changed, 223 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 225dd44..79249fa 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Role Name ========= -A brief description of the role goes here. +This role is supposed to deploy a new OpenIndiana Zone on a yada... Requirements ------------ diff --git a/defaults/main.yml b/defaults/main.yml index 55d9505..7fcda8a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,72 @@ --- -# defaults file for oi-zone \ No newline at end of file +# defaults file for oi-zone +oizone: + name: oizone + zoneroot: /export/zones/ + autoboot: "true" + bootargs: # -v + iptype: exclusive + cpus: dedicated # dedicated or capped-cpu + ncpus: 1 + mem: capped-memory # or nil + ram: 1G + swap: 1G + locked: 1G + brand: ipkg + filesystems: + - path: /export/zones/oizone + type: zoneroot + zfscreate: true + zfs_extra_properties: + refquota: 10G + - path: apppool/oizone/datavol1 + type: volume + zfscreate: true + zfs_extra_properties: + volsize: 5G + - path: apppool/oizone/dataset1 + type: dataset + zfscreate: true + zfs_extra_properties: + quota: 2G + - path: /disk1 + type: lofs + mountpoint: /hostdisks/disk1 + zfscreate: false + options: + - ro + - nodevices + nics: + - physical: ixgbe0 + logical: oizoneint0 + vlan: 100 + address: dhcp # can be "dhcp" or a regular IP address + addrsuffix: v4 # can be a string, interface0/suffix will be the ipadm create-addr + kvm: + vnc: "on" + bootorder: cd + sysding: + timezone: UTC + locale: C + ip: + routes: + - target: default # can be a CIDR or a host ip or "default" + router: 172.18.0.200 # IP of the router + dns: + nameservers: + - 1.1.1.1 + - 8.8.8.8 + search: + - example.com + - openindiana.org + domain: example.com + users: + - name: root + hashedpassword: "$5$foobar...." + - name: localadm + uid: 100 + gid: 10 + shell: /usr/bin/bash + gecos: "Local Admin Account" + home: /export/home/localadm + hashedpassword: "$5$barfoo...." diff --git a/meta/main.yml b/meta/main.yml index 227ad9c..c8148b0 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,7 +1,7 @@ galaxy_info: - author: your name - description: your role description - company: your company (optional) + author: Olaf Bohlen + description: create zones on OpenIndiana + company: eenfach.de # If the issue tracker for your role is not on github, uncomment the # next line and provide a value @@ -14,9 +14,9 @@ # - GPL-3.0-only # - Apache-2.0 # - CC-BY-4.0 - license: license (GPL-2.0-or-later, MIT, etc) + license: license BSD-3-Clause - min_ansible_version: 2.9 + min_ansible_version: 2.7 # If this a Container Enabled role, provide the minimum Ansible Container version. # min_ansible_container_version: @@ -39,15 +39,20 @@ # - 7 # - 99.99 - galaxy_tags: [] + galaxy_tags: # List tags for your role here, one per line. A tag is a keyword that describes # and categorizes the role. Users find roles by searching for tags. Be sure to # remove the '[]' above, if you add tags to this list. # # NOTE: A tag is limited to a single word comprised of alphanumeric characters. # Maximum 20 tags per role. - + - zones + - illumos + - openindiana + - oi + - hipster + dependencies: [] # List your role dependencies here, one per line. Be sure to remove the '[]' above, # if you add dependencies to this list. - \ No newline at end of file + diff --git a/tasks/main.yml b/tasks/main.yml index 4442303..fd4045c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,112 @@ --- -# tasks file for oi-zone \ No newline at end of file +# tasks file for oi-zone +- name: create VNICs + dladm_vnic: + name: "{{ item['logical'] }}" + link: "{{ item['physical'] }}" + vlan: "{{ item['vlan'] }}" + loop: "{{ oizone['nics'] }}" + +- name: create filesystems + zfs: + name: "{{ item['path'] }}" + state: present + zfs_extra_properties: "{{ item['zfs_extra_properties'] }}" + loop: "{{ oizone['filesystems'] }}" + when: zfscreate + +- name: set up VM zones for master + solaris_zone: + name: "{{ oizone['name'] }}" + state: installed + path: "{{ oizone['zoneroot'] }}/{{ oizone['name'] }}" + config: > + set brand={{ oizone['brand'] }}; + set autoboot={{ oizone['autoboot'] }}; + {% if oizone['bootargs'] %} + set bootargs={{ oizone['bootargs'] }}; + {% endif %} + set ip-type={{ oizone['iptype'] }}; + {% for nic in oizone['nics'] %} + add net; + set physical={{ nic['logical'] }}; + {% if {{ oizone['iptype'] == "shared" %} + set address={{ nic['address'] }}; + {% endif %} + end; + {% endfor %} + {% for disk in vmconfig[outer_item]['disks'] %} + add device; + set match="/dev/zvol/rdsk/localstripe/vm/{{ outer_item }}d{{ disk['instance'] }}"; + end; + add attr; + set name="{{ disk['label'] }}"; + set type="string"; + set value="localstripe/vm/{{ outer_item }}d{{ disk['instance'] }}"; + end; + {% endfor %} + {% if oizone['cpus'] == "dedicated" %} + add dedicated-cpu; + set ncpus={{ oizone['ncpus'] }}; + end; + {% endif %} + {% if oizone['cpus'] == "capped-cpu" %} + add capped-cpu; + set ncpus={{ oizone['ncpus'] }}; + end; + {% endif %} + {% if oizone['mem'] == "capped-memory" %} + add capped-memory; + set physical={{ oizone['ram'] }}; + set swap={{ oizone['swap'] }}; + set locked={{ oizone['locked'] }}; + end; + {% endif %} + {% for dataset in oizone['filesystems'] %} + {% if dataset['type'] == "dataset" %} + add dataset; + set name={{ dataset['path'] }}; + end; + {% endif %} + {% if dataset['type'] == "lofs" %} + add fs; + set special={{ dataset['path'] }}; + set dir={{ dataset['mountpoint'] }}; + set type="lofs"; + {% for option in database['options'] %} + add options {{ option }}; + {% endfor %} + end; + {% endif %} + {% if dataset['type'] == "volume" %} + add device; + set match=/dev/zvol/rdsk/{{ dataset['path'] }}; + end; + {% endif %} + {% endfor %} + {% if oizone['brand'] == "kvm" %} + add attr; + set name="bootorder"; + set type="string"; + set value="{{ oizone['kvm']['bootorder'] }}"; + add attr; + set name="vnc"; + set type="string"; + set value="{{ oizone['kvm']['vnc'] }}"; + end; + add attr; + set name="vcpus"; + set type="string"; + set value="{{ oizone['ncpus'] }}"; + end; + add attr; + set name="ram"; + set type="string"; + set value="{{ oizone['ram'] }}"; + end; + {% endif %} + +- name: create a sysding.conf + template: + dest: "{{ oizone['zoneroot'] }}/{{ oizone['name'] }}/root/etc/sysding.conf" + src: sysding.j2 diff --git a/templates/sysding.j2 b/templates/sysding.j2 new file mode 100644 index 0000000..9d3e62c --- /dev/null +++ b/templates/sysding.j2 @@ -0,0 +1,27 @@ +setup_timezone "{{ oizone['sysding']['timezone'] }}" +setup_locale "{{ oizone['sysding']['locale'] }}" +{% if oizone['sysding']['nfs4domain'] %} +setup_nfs4domain "{{ oizone['sysding']['nfs4domain'] }}" +{% endif %} + +{% for user in oizone['sysding']['users'] %} +{% if user['name'] != "root" %} +setup_user_account {{ user['name'] }} {{ user['uid'] }} {{ user['gid'] }} {{ user['gecos'] }} {{ user['home'] }} {{ user['shell'] }} +mkdir -p {{ user['home'] }} +chmod {{ user['name'] }}:{{ user['gid'] }} {{ user['home'] }} +{% endif %} +setup_user_password {{ user['name'] }} '{{ user["hashedpassword"] }}' +{% endfor %} +{% if oizone['iptype'] == "exclusive-ip" %} +{% for nic in oizone['nics'] %} +setup_interface {{ nic['logical'] }} {{ nic['addrsuffix'] }} {{ nic['address'] }} +{% endfor %} +{% endif %} + +{% for route in oizone['sysding']['ip']['routes'] %} +setup_route {{ route['target'] }} {{ route['router'] }} +{% endfor %} + +{% if oizone['sysding']['dns'] %} +setup_ns_dns "{{ oizone['sysding']['dns']['domain'] }}" "{{ oizone['sysding']['dns']['search'] | join(' ') }}" "{{ oizone['sysding']['dns']['nameservers'] | join(' ') }}" +{% endif %} -- Gitblit v1.9.3