Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert playbook to configure juju into a role. #316

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 2 additions & 105 deletions playbooks/juju/pre.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions roles/juju-setup/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
juju_snap_channel: "2.9/stable"
104 changes: 104 additions & 0 deletions roles/juju-setup/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions zuul.d/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@
cleanup-run: playbooks/juju/cleanup.yaml
secrets:
- serverstack_cloud
vars:
juju_snap_channel: "2.9/stable"

- job:
name: func-target
Expand Down
Loading