Skip to content

Commit

Permalink
Trick ansible in loading mock data
Browse files Browse the repository at this point in the history
Fetch the remote mock file, inject it locally, and call include_vars to
load the mocked data.
  • Loading branch information
cjeanner authored and openshift-merge-bot[bot] committed May 17, 2024
1 parent d249f0b commit 6c1eb3b
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions ci/playbooks/validate-architecture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
['~/bin',
ansible_env.PATH] | join(':')
}}
_mock_file: >-
{{
[cifmw_architecture_repo, 'automation/mocks',
cifmw_architecture_scenario ~ '.yaml'] | path_join
}}
pre_tasks:
- name: Assert we have the bare minimum to run
ansible.builtin.assert:
Expand All @@ -48,22 +53,6 @@
ansible.builtin.import_role:
name: 'ci_setup'

- name: Install kustomize
when:
- zuul.projects is defined
- zuul.projects['github.com/openstack-k8s-operators/install_yamls'] is defined
vars:
_chdir: >-
{{
[zuul.projects['github.com/openstack-k8s-operators/install_yamls'].src_dir,
'devsetup'] | path_join
}}
ansible.builtin.command:
chdir: "{{ _chdir }}"
cmd: >-
ansible-playbook -i localhost, -c local
download_tools.yaml --tags kustomize
- name: Create needed directories
ansible.builtin.file:
path: "{{ item }}"
Expand All @@ -73,18 +62,37 @@
- "{{ cifmw_basedir }}/logs"
- "{{ cifmw_basedir }}/artifacts"

- name: Check if we have a mock file
register: _mock_state
ansible.builtin.stat:
path: "{{ _mock_file }}"

- name: Copy file to facts.d as YAML
when:
- _mock_state.stat.exists
block:
- name: Slurp file from remote
register: _mock_content
ansible.builtin.slurp:
src: "{{ _mock_file }}"

- name: Copy file on localhost
delegate_to: localhost
ansible.builtin.copy:
dest: "{{ lookup('env', 'HOME') }}/{{ cifmw_architecture_scenario }}.yml }}"
mode: "0644"
content: "{{ _mock_content.content | b64decode }}"

- name: Include var file
ansible.builtin.include_vars:
file: "{{ lookup('env', 'HOME') }}/{{ cifmw_architecture_scenario }}.yml }}"

- name: Ensure kustomize_deploy is bootstraped
ansible.builtin.import_role:
name: "kustomize_deploy"
tasks_from: "check_requirements.yml"
tasks:
- name: Output kubectl data
ansible.builtin.shell:
cmd: |
which kubectl
kubectl version --client=true
kubectl kustomize --help

tasks:
- name: Load networking mapper environment
ansible.builtin.import_role:
name: "networking_mapper"
Expand Down

0 comments on commit 6c1eb3b

Please sign in to comment.