Skip to content

Commit 07488b1

Browse files
committed
Refactor bootstrap role to align with Ansible best practices
- Use fully qualified module names (ansible.builtin.*) throughout - Convert boolean values from yes/no to true/false - Improve task names with proper capitalization and clarity - Replace ansible.builtin.shell with ansible.builtin.command for oc commands - Replace mv command with ansible.builtin.copy module using remote_src - Add retry logic (5 retries, 5s delay) to observability operator wait task - Fix OCP inventory structure to use .json consistently for local and remote sources - Add explicit cmd parameter to all command/shell tasks - Add mode and become flags where appropriate This ensures consistency, better error handling, and alignment with Ansible best practices for module usage and task naming conventions. AI Model: Generated using Auto (agent router designed by Cursor)
1 parent aa0c18e commit 07488b1

2 files changed

Lines changed: 41 additions & 28 deletions

File tree

ansible/roles/bootstrap/tasks/includes/download_ocp_inventory.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
# It only downloads if the file is not present locally
44

55
- name: Check if local OCP inventory file exists
6-
stat:
6+
ansible.builtin.stat:
77
path: "{{ ocp_inventory_local_path | default('') }}"
88
register: local_inventory_file
99
when: ocp_inventory_local_path is defined and ocp_inventory_local_path | length > 0
1010

1111
- name: Read local OCP inventory file if present
12-
set_fact:
12+
ansible.builtin.set_fact:
1313
ocp_inventory:
14-
content: "{{ lookup('file', ocp_inventory_local_path) }}"
14+
json: "{{ lookup('file', ocp_inventory_local_path) | from_json }}"
1515
when:
1616
- ocp_inventory_local_path is defined
1717
- ocp_inventory_local_path | length > 0
1818
- local_inventory_file.stat.exists
1919

2020
- name: Download OCP inventory file (scalelab)
21-
uri:
21+
ansible.builtin.uri:
2222
url: "https://wiki.scalelab.redhat.com/instack/{{ cloud }}_ocpinventory.json"
2323
return_content: true
2424
register: ocpinventory_scale
@@ -27,7 +27,7 @@
2727
- not (local_inventory_file.stat.exists | default(false))
2828

2929
- name: Download OCP inventory file (performancelab)
30-
uri:
30+
ansible.builtin.uri:
3131
url: "https://wiki.rdu3.labs.perfscale.redhat.com/instack/{{ cloud }}_ocpinventory.json"
3232
return_content: true
3333
register: ocpinventory_alias
@@ -36,6 +36,6 @@
3636
- not (local_inventory_file.stat.exists | default(false))
3737

3838
- name: Set fact for OCP inventory (from download)
39-
set_fact:
39+
ansible.builtin.set_fact:
4040
ocp_inventory: "{{ ocpinventory_scale if lab == 'scalelab' else ocpinventory_alias }}"
4141
when: not (local_inventory_file.stat.exists | default(false))
Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,61 @@
11
---
22
- name: Flush iptables rules before deployment
3-
command: iptables -F
4-
become: yes
5-
ignore_errors: yes
3+
ansible.builtin.command:
4+
cmd: iptables -F
5+
become: true
6+
ignore_errors: true
67

7-
- name: clean up the dt_path
8-
file:
8+
- name: Clean up the dt_path
9+
ansible.builtin.file:
910
path: "{{ dt_path }}"
1011
state: absent
1112

12-
- name: clone architecture repo
13-
git:
13+
- name: Clone architecture repository
14+
ansible.builtin.git:
1415
repo: https://github.com/masco/architecture.git
1516
dest: "{{ dt_path }}"
1617
version: bm-ocp
17-
force: yes
18+
force: true
1819

19-
- name: download kustomize lib
20-
shell:
21-
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
20+
- name: Download kustomize library
21+
ansible.builtin.shell:
22+
cmd: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
2223

23-
- name: move the kustomize to usr-bin
24-
shell:
25-
mv kustomize /usr/bin/.
24+
- name: Move kustomize to /usr/bin
25+
ansible.builtin.copy:
26+
src: kustomize
27+
dest: /usr/bin/kustomize
28+
remote_src: true
29+
mode: '0755'
30+
become: true
2631

2732
- name: Download or load OCP inventory
28-
include_tasks: includes/download_ocp_inventory.yml
33+
ansible.builtin.include_tasks:
34+
file: includes/download_ocp_inventory.yml
2935

30-
- name: enable ip forward for ovn-kubernets
31-
shell: |
36+
- name: Enable IP forward for OVN-Kubernetes
37+
ansible.builtin.command:
38+
cmd: |-
39+
{%raw%}
3240
oc patch network.operator cluster -p '{"spec":{"defaultNetwork": {"ovnKubernetesConfig":{"gatewayConfig":{"ipForwarding": "Global"}}}}}' --type=merge
41+
{%endraw%}
3342

3443
- name: Setup observability operator
3544
block:
3645
- name: Copy observability operator subscription template
37-
template:
46+
ansible.builtin.template:
3847
src: subscriptions.yaml
3948
dest: "{{ dt_path }}/subscriptions.yaml"
4049

4150
- name: Apply observability operator subscription
42-
shell: |
43-
oc apply -f {{ dt_path }}/subscriptions.yaml
51+
ansible.builtin.command:
52+
cmd: oc apply -f {{ dt_path }}/subscriptions.yaml
4453

4554
- name: Wait for observability operator to be available
46-
shell: |
47-
oc wait deployments/observability-operator --for condition=Available --timeout=300s -n openshift-operators
55+
ansible.builtin.command:
56+
cmd: oc wait deployments/observability-operator --for condition=Available --timeout=300s -n openshift-operators
57+
register: observability_wait
58+
retries: 5
59+
delay: 5
60+
until: observability_wait.rc == 0
4861
when: telemetry | default(true)

0 commit comments

Comments
 (0)