From 08086721e2c45ff3f89dd23b42a4dd9fadfe9f96 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Tue, 13 Feb 2024 10:45:37 -0300 Subject: [PATCH] Convert playbook to configure juju into a role. Rewriting the configure juju code into a role allows the definition of a variable with a default, instead of just a variable set at the job definition level. The expectation is that this will allow to override juju_snap_channel in osci.yaml. --- playbooks/juju/pre.yaml | 107 +--------------------------- roles/juju-setup/defaults/main.yaml | 1 + roles/juju-setup/tasks/main.yaml | 104 +++++++++++++++++++++++++++ zuul.d/jobs.yaml | 2 - 4 files changed, 107 insertions(+), 107 deletions(-) create mode 100644 roles/juju-setup/defaults/main.yaml create mode 100644 roles/juju-setup/tasks/main.yaml diff --git a/playbooks/juju/pre.yaml b/playbooks/juju/pre.yaml index 15beadd..b61df04 100644 --- a/playbooks/juju/pre.yaml +++ b/playbooks/juju/pre.yaml @@ -1,106 +1,3 @@ - hosts: all - tasks: - - name: hack around juju's reluctance to deploy misnamed directories - copy: - src: "/home/ubuntu/{{ zuul.project.src_dir }}/" - dest: "/home/ubuntu/{{ zuul.project.src_dir | replace('charm-', '') }}" - remote_src: yes - # NOTE(freyes): fixes the error below when running `juju` in a fresh - # environment. - # ERROR cannot create juju home directory: mkdir /home/ubuntu/.local/share: permission denied - # WARNING Installing Juju in a strictly confined Snap. To ensure correct operation, create the ~/.local/share/juju directory manually. - - name: Create ~/.local/share/juju directory to run Juju snap in strict mode - ansible.builtin.file: - path: /home/ubuntu/.local/share/juju - state: directory - owner: ubuntu - group: ubuntu - mode: '0700' - - name: 'install crashdump' - become: true - snap: - name: juju-crashdump - classic: yes - register: result - until: result is not failed - retries: 10 - delay: 10 - # Setup Juju - - name: 'install juju' - become: true - snap: - name: juju - # NOTE(freyes): Juju's '2.9' snap track publishes a snap with the - # classic confinement, while juju>=3.1 uses a strict confinement, - # instead of asking users to understand this, we encapsulate this - # information into this inline-if where if the juju_snap_channel has the - # '2.9/' prefix the classic field is set to True, otherwise False. - classic: "{{ juju_snap_channel is defined and juju_snap_channel.startswith('2.9/') }}" - channel: "{{ juju_snap_channel }}" - register: result - until: result is not failed - retries: 10 - delay: 10 - - name: Install libpq-dev - become: true - apt: - name: libpq-dev - - name: Install libmysqlclient-dev - become: true - apt: - name: libmysqlclient-dev - - name: Install libxml2-dev - become: true - apt: - name: libxml2-dev - - name: Install libxslt1-dev - become: true - apt: - name: libxslt1-dev - - name: Install qemu-utils - become: true - apt: - name: qemu-utils - - name: Render juju clouds.yaml - template: - src: clouds.yaml.j2 - dest: clouds.yaml - - name: Add cloud - command: /snap/bin/juju add-cloud --client {{ serverstack_cloud.region_name }} clouds.yaml - - name: 'render credentials.yaml' - template: - src: credentials.yaml.j2 - dest: credentials.yaml - - name: Add credential - command: /snap/bin/juju add-credential {{ serverstack_cloud.region_name }} --client -f credentials.yaml - - name: Clone charm-test-infra - command: git clone https://github.com/openstack-charmers/charm-test-infra /home/ubuntu/charm-test-infra - - name: 'Bootstrap Controller' - command: | - /snap/bin/juju bootstrap \ - --bootstrap-constraints="virt-type=kvm cores=4 mem=8G" \ - --constraints=virt-type=kvm \ - --auto-upgrade=false \ - --model-default=/home/ubuntu/charm-test-infra/juju-configs/model-default-serverstack.yaml \ - --config=/home/ubuntu/charm-test-infra/juju-configs/controller-default.yaml \ - {{ serverstack_cloud.region_name }}/{{ serverstack_cloud.region_name }} - - name: 'Configure cloudinit-userdata model-default' - shell: - cmd: | - cat > /home/ubuntu/cloudinit-userdata.yaml << EOF - cloudinit-userdata: | - apt: - conf: | - APT { - Get { - Always-Include-Phased-Updates 'true'; - } - } - preruncmd: - - sed -i "/^ExecStart.*systemd-resolved/a Environment=SYSTEMD_LOG_LEVEL=debug" /lib/systemd/system/systemd-resolved.service - - systemctl daemon-reload - - systemctl restart systemd-resolved - EOF - /snap/bin/juju model-default /home/ubuntu/cloudinit-userdata.yaml - args: - executable: /bin/bash + roles: + - juju-setup diff --git a/roles/juju-setup/defaults/main.yaml b/roles/juju-setup/defaults/main.yaml new file mode 100644 index 0000000..b6a4f0d --- /dev/null +++ b/roles/juju-setup/defaults/main.yaml @@ -0,0 +1 @@ +juju_snap_channel: "2.9/stable" diff --git a/roles/juju-setup/tasks/main.yaml b/roles/juju-setup/tasks/main.yaml new file mode 100644 index 0000000..1e52ac9 --- /dev/null +++ b/roles/juju-setup/tasks/main.yaml @@ -0,0 +1,104 @@ +- name: hack around juju's reluctance to deploy misnamed directories + copy: + src: "/home/ubuntu/{{ zuul.project.src_dir }}/" + dest: "/home/ubuntu/{{ zuul.project.src_dir | replace('charm-', '') }}" + remote_src: yes +# NOTE(freyes): fixes the error below when running `juju` in a fresh +# environment. +# ERROR cannot create juju home directory: mkdir /home/ubuntu/.local/share: permission denied +# WARNING Installing Juju in a strictly confined Snap. To ensure correct operation, create the ~/.local/share/juju directory manually. +- name: Create ~/.local/share/juju directory to run Juju snap in strict mode + ansible.builtin.file: + path: /home/ubuntu/.local/share/juju + state: directory + owner: ubuntu + group: ubuntu + mode: '0700' +- name: 'install crashdump' + become: true + snap: + name: juju-crashdump + classic: yes + register: result + until: result is not failed + retries: 10 + delay: 10 +# Setup Juju +- name: 'install juju' + become: true + snap: + name: juju + # NOTE(freyes): Juju's '2.9' snap track publishes a snap with the + # classic confinement, while juju>=3.1 uses a strict confinement, + # instead of asking users to understand this, we encapsulate this + # information into this inline-if where if the juju_snap_channel has the + # '2.9/' prefix the classic field is set to True, otherwise False. + classic: "{{ juju_snap_channel is defined and juju_snap_channel.startswith('2.9/') }}" + channel: "{{ juju_snap_channel }}" + register: result + until: result is not failed + retries: 10 + delay: 10 +- name: Install libpq-dev + become: true + apt: + name: libpq-dev +- name: Install libmysqlclient-dev + become: true + apt: + name: libmysqlclient-dev +- name: Install libxml2-dev + become: true + apt: + name: libxml2-dev +- name: Install libxslt1-dev + become: true + apt: + name: libxslt1-dev +- name: Install qemu-utils + become: true + apt: + name: qemu-utils +- name: Render juju clouds.yaml + template: + src: clouds.yaml.j2 + dest: clouds.yaml +- name: Add cloud + command: /snap/bin/juju add-cloud --client {{ serverstack_cloud.region_name }} clouds.yaml +- name: 'render credentials.yaml' + template: + src: credentials.yaml.j2 + dest: credentials.yaml +- name: Add credential + command: /snap/bin/juju add-credential {{ serverstack_cloud.region_name }} --client -f credentials.yaml +- name: Clone charm-test-infra + command: git clone https://github.com/openstack-charmers/charm-test-infra /home/ubuntu/charm-test-infra +- name: 'Bootstrap Controller' + command: | + /snap/bin/juju bootstrap \ + --bootstrap-constraints="virt-type=kvm cores=4 mem=8G" \ + --constraints=virt-type=kvm \ + --auto-upgrade=false \ + --model-default=/home/ubuntu/charm-test-infra/juju-configs/model-default-serverstack.yaml \ + --config=/home/ubuntu/charm-test-infra/juju-configs/controller-default.yaml \ + {{ serverstack_cloud.region_name }}/{{ serverstack_cloud.region_name }} +- name: 'Configure cloudinit-userdata model-default' + shell: + cmd: | + cat > /home/ubuntu/cloudinit-userdata.yaml << EOF + cloudinit-userdata: | + apt: + conf: | + APT { + Get { + Always-Include-Phased-Updates 'true'; + } + } + preruncmd: + - sed -i "/^ExecStart.*systemd-resolved/a Environment=SYSTEMD_LOG_LEVEL=debug" /lib/systemd/system/systemd-resolved.service + - systemctl daemon-reload + - systemctl restart systemd-resolved + EOF + /snap/bin/juju model-default /home/ubuntu/cloudinit-userdata.yaml + args: + executable: /bin/bash diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index b8d6c99..e5d029a 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -224,8 +224,6 @@ cleanup-run: playbooks/juju/cleanup.yaml secrets: - serverstack_cloud - vars: - juju_snap_channel: "2.9/stable" - job: name: func-target