Skip to content

Commit 0829a0c

Browse files
committed
Test after ansible-lint
1 parent 772de2c commit 0829a0c

File tree

2 files changed

+81
-46
lines changed

2 files changed

+81
-46
lines changed

etc/kayobe/ansible/octavia-amphora-image-build.yml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
amphora_image_dest: "{{ image_cache_path }}/amphora-x64-haproxy-{{ openstack_release }}.qcow2"
77
tasks:
88
- name: Install EPEL
9-
package:
9+
ansible.builtin.package:
1010
name: epel-release
1111
become: true
1212
when:
@@ -29,24 +29,25 @@
2929
Debian:
3030
- qemu-utils
3131
- kpartx
32-
package:
32+
ansible.builtin.package:
3333
name: "{{ packages_common + packages_for_os_family[ansible_facts.os_family] }}"
3434

3535
- name: Create a temporary directory
36-
tempfile:
36+
ansible.builtin.tempfile:
3737
state: directory
3838
register: tempfile_result
3939

40-
- block:
40+
- name: Build Amphora image
41+
block:
4142
- name: Check whether the image cache directory exists
42-
stat:
43+
ansible.builtin.stat:
4344
path: "{{ image_cache_path }}"
44-
get_checksum: False
45-
mime: False
45+
get_checksum: false
46+
mime: false
4647
register: image_cache_stat
4748

4849
- name: Ensure the image cache directory exists
49-
file:
50+
ansible.builtin.file:
5051
path: "{{ image_cache_path }}"
5152
state: directory
5253
owner: "{{ ansible_facts.user_uid }}"
@@ -59,46 +60,48 @@
5960
- name: Set path facts
6061
vars:
6162
work_path: "{{ tempfile_result.path }}"
62-
set_fact:
63+
ansible.builtin.set_fact:
6364
src_path: "{{ work_path }}/octavia"
6465
venv_path: "{{ work_path }}/venv"
6566
work_path: "{{ work_path }}"
6667

6768
- name: Clone Octavia source code
68-
git:
69+
ansible.builtin.git:
6970
depth: 1
7071
dest: "{{ src_path }}"
71-
repo: "https://opendev.org/openstack/octavia"
72+
repo: https://opendev.org/openstack/octavia
7273
version: "{{ openstack_branch }}"
7374

7475
- name: Install diskimage-builder in a virtual environment
75-
pip:
76+
ansible.builtin.pip:
7677
name: diskimage-builder
7778
extra_args: "{% if amphora_dib_upper_constraints_file %}-c {{ amphora_dib_upper_constraints_file }}{% endif %}"
7879
virtualenv: "{{ venv_path }}"
79-
virtualenv_command: "python3.{{ ansible_facts.python.version.minor }} -m venv"
80+
virtualenv_command: python3.{{ ansible_facts.python.version.minor }} -m venv
8081

8182
- name: Create build log file (/var/log/octavia-amphora-image-build.log)
82-
file:
83+
ansible.builtin.file:
8384
path: /var/log/octavia-amphora-image-build.log
8485
state: touch
8586
owner: "{{ ansible_facts.user_uid }}"
8687
group: "{{ ansible_facts.user_gid }}"
8788
become: true
8889

8990
- name: Create the Amphora image
90-
shell:
91-
cmd: ". {{ venv_path }}/bin/activate && ./diskimage-create.sh -i ubuntu-minimal -s 3 -g {{ openstack_branch }} >> /var/log/octavia-amphora-image-build.log 2>&1"
91+
ansible.builtin.shell:
92+
cmd: >-
93+
source {{ venv_path }}/bin/activate &&
94+
./diskimage-create.sh -i ubuntu-minimal -s 3 -g {{ openstack_branch }} >> /var/log/octavia-amphora-image-build.log 2>&1
9295
chdir: "{{ src_path }}/diskimage-create"
9396
changed_when: true
9497

9598
- name: Copy image to image store
96-
copy:
99+
ansible.builtin.copy:
97100
src: "{{ src_path }}/diskimage-create/amphora-x64-haproxy.qcow2"
98101
dest: "{{ amphora_image_dest }}"
99102
remote_src: true
100103
always:
101104
- name: Remove temporary files
102-
file:
105+
ansible.builtin.file:
103106
path: "{{ work_path }}"
104107
state: absent
Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,118 @@
11
---
2-
- name: Register an Octavia Amphora image in Glance
2+
- name: Octavia credentials precheck
33
gather_facts: yes
4-
hosts: "{{ amphora_builder_group | default('seed') }}"
5-
vars:
6-
venv: "{{ virtualenv_path }}/octavia-amphora"
4+
hosts: localhost
75
tasks:
86
- name: Fail if not using octavia user and service project
9-
fail:
7+
ansible.builtin.fail:
108
msg: >-
119
Source the octavia-openrc.sh file before executing this playbook
1210
when: >-
1311
lookup('env', 'OS_USERNAME') != 'octavia' or
1412
lookup('env', 'OS_PROJECT_NAME') != 'service'
1513
14+
- name: Download Amphora image from Ark
15+
ansible.builtin.import_playbook: pulp-amphora-image-download.yml
16+
when: download_from_ark | default(true) | bool
17+
18+
- name: Register an Octavia Amphora image in Glance
19+
gather_facts: yes
20+
hosts: localhost
21+
vars:
22+
venv: "{{ virtualenv_path }}/octavia-amphora"
23+
image_path: "/tmp/amphora-x64-haproxy.qcow2"
24+
tasks:
1625
- name: Get image checksum
17-
stat:
18-
path: "{{ image_cache_path }}/amphora-x64-haproxy-{{ openstack_release }}.qcow2"
26+
vars:
27+
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
28+
ansible.builtin.stat:
29+
path: "{{ image_path }}"
1930
checksum_algorithm: md5
2031
changed_when: false
2132
register: image_checksum
33+
delegate_to: "{{ groups['controllers'][0] }}"
34+
become: true
2235

2336
- name: Assert that Amphora image exists
24-
assert:
37+
vars:
38+
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
39+
ansible.builtin.assert:
2540
that: image_checksum.stat.exists
2641
fail_msg: |
27-
The amphora image: {{ image_cache_path }}/amphora-x64-haproxy-{{ openstack_release }}.qcow2
28-
does not exist. Did you build the image?
42+
The amphora image: {{ image_path }}
43+
does not exist. Did you download or build the image?
44+
delegate_to: "{{ groups['controllers'][0] }}"
45+
46+
- name: Ensure packages for python-openstackclient are installed
47+
become: true
48+
vars:
49+
required_packages:
50+
- python3-venv
51+
- python3-dev
52+
- gcc
53+
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
54+
ansible.builtin.package:
55+
name: "{{ required_packages }}"
56+
delegate_to: "{{ groups['controllers'][0] }}"
2957

3058
- name: Set up openstack virtualenv
31-
pip:
59+
vars:
60+
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
61+
ansible.builtin.pip:
3262
virtualenv: "{{ venv }}"
3363
virtualenv_command: python3 -m venv
3464
name:
3565
- openstacksdk
3666
- python-openstackclient
3767
state: latest
3868
extra_args: "{% if openstacksdk_upper_constraints_file %}-c {{ openstacksdk_upper_constraints_file }}{% endif %}"
69+
delegate_to: "{{ groups['controllers'][0] }}"
3970

4071
- name: Query Octavia Amphora image
4172
vars:
4273
ansible_python_interpreter: "{{ venv }}/bin/python"
43-
os_image_info:
74+
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
75+
openstack.cloud.image_info:
4476
auth_type: password
4577
auth: "{{ openstack_auth }}"
4678
ca_cert: "{{ openstack_cacert }}"
4779
interface: "{{ openstack_interface }}"
4880
image: amphora-x64-haproxy
4981
register: image_info
82+
delegate_to: "{{ groups['controllers'][0] }}"
5083

51-
- name: Ensure Octavia Amphora image is renamed
84+
- name: Ensure old Octavia Amphora image is renamed
5285
vars:
5386
ansible_python_interpreter: "{{ venv }}/bin/python"
54-
shell:
87+
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
88+
ansible.builtin.command:
5589
cmd: >-
5690
{{ venv }}/bin/openstack image set amphora-x64-haproxy --name amphora-x64-haproxy-{{ ansible_facts.date_time.iso8601_basic_short }}
5791
when:
58-
- image_info.image
59-
- image_info.image.checksum != image_checksum.stat.checksum
92+
- image_info.images | length != 0
93+
- image_info.images[0].checksum != image_checksum.stat.checksum
6094
changed_when: true
6195
environment: "{{ openstack_auth_env }}"
96+
delegate_to: "{{ groups['controllers'][0] }}"
6297

63-
- name: Ensure Octavia Amphora image is registered
98+
- name: Ensure new Octavia Amphora image is registered
6499
vars:
65100
ansible_python_interpreter: "{{ venv }}/bin/python"
66-
os_image:
101+
ansible_host: "{{ hostvars[groups['controllers'][0]].ansible_host }}"
102+
openstack.cloud.image:
67103
auth_type: password
68104
auth: "{{ openstack_auth }}"
69105
ca_cert: "{{ openstack_cacert }}"
70106
interface: "{{ openstack_interface }}"
71107
name: amphora-x64-haproxy
108+
tags: ["amphora"]
72109
container_format: bare
73110
disk_format: qcow2
74-
is_public: no
75-
filename: "{{ image_cache_path }}/amphora-x64-haproxy-{{ openstack_release }}.qcow2"
111+
is_public: false
112+
filename: "{{ image_path }}"
76113
properties:
77114
hw_architecture: x86_64
78115
hw_rng_model: virtio
79-
80-
# FIXME: Use 'tags' parameter of os_image module available from
81-
# openstack.cloud.image 1.5.0.
82-
- name: Ensure Octavia Amphora image is tagged
83-
shell:
84-
cmd: >-
85-
{{ venv }}/bin/openstack image set amphora-x64-haproxy --tag amphora
86-
environment: "{{ openstack_auth_env }}"
116+
when: image_info.images | length == 0 or (image_info.images | length != 0 and image_info.images[0].checksum != image_checksum.stat.checksum)
117+
become: true
118+
delegate_to: "{{ groups['controllers'][0] }}"

0 commit comments

Comments
 (0)