From c5c30cdcf742caf69cfc86d7c94be85c99b3c55e Mon Sep 17 00:00:00 2001 From: Teodoro Cook Date: Sun, 21 Jan 2024 20:27:33 -0600 Subject: [PATCH] Add ip configuration test to hostfile scenario (#37) --- .github/workflows/hostfile.yml | 1 + galaxy.yml | 2 +- molecule/hostfile/converge.yml | 5 ++ molecule/hostfile/molecule.yml | 11 +++-- molecule/hostfile/side_effect.yml | 77 +++++++++++++++++++++++++++++++ molecule/hostfile/verify.yml | 11 +++++ roles.yml | 2 +- 7 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 molecule/hostfile/converge.yml create mode 100644 molecule/hostfile/side_effect.yml create mode 100644 molecule/hostfile/verify.yml diff --git a/.github/workflows/hostfile.yml b/.github/workflows/hostfile.yml index c994eac..46b9a37 100644 --- a/.github/workflows/hostfile.yml +++ b/.github/workflows/hostfile.yml @@ -7,6 +7,7 @@ on: - master paths: - 'playbooks/prepare.yml' + - 'molecule/hostfile/*.yml' - '.github/workflows/hostfile.yml' jobs: diff --git a/galaxy.yml b/galaxy.yml index a3ad3e4..e561822 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: nephelaiio name: mongodb -version: 0.2.5 +version: 0.2.6 readme: README.md authors: - Ted Cook diff --git a/molecule/hostfile/converge.yml b/molecule/hostfile/converge.yml new file mode 100644 index 0000000..9d9d53b --- /dev/null +++ b/molecule/hostfile/converge.yml @@ -0,0 +1,5 @@ +--- +- name: Import install playbook + import_playbook: nephelaiio.mongodb.install + vars: + mongodb_hosts_manage: true diff --git a/molecule/hostfile/molecule.yml b/molecule/hostfile/molecule.yml index e8b1e5d..24a2603 100644 --- a/molecule/hostfile/molecule.yml +++ b/molecule/hostfile/molecule.yml @@ -52,13 +52,18 @@ provisioner: playbooks: create: ../common/create.yml prepare: ../common/prepare.yml - converge: ../common/install.yml - verify: ../common/verify.yml destroy: ../common/destroy.yml cleanup: ../common/cleanup.yml config_options: defaults: callbacks_enabled: ansible.posix.profile_tasks + inventory: + hosts: + all: + vars: + mongodb_cluster_state_zero: /tmp/state.0.yml + mongodb_cluster_state_one: /tmp/state.1.yml + mongodb_cluster_state_two: /tmp/state.2.yml verifier: name: ansible scenario: @@ -77,5 +82,3 @@ scenario: - converge - side_effect - verify - - destroy - - cleanup diff --git a/molecule/hostfile/side_effect.yml b/molecule/hostfile/side_effect.yml new file mode 100644 index 0000000..f3320b0 --- /dev/null +++ b/molecule/hostfile/side_effect.yml @@ -0,0 +1,77 @@ +--- +- name: Gather cluster facts + hosts: mongodb_mongos + become: true + tasks: + - name: Gather MongoDB existing replica set members + community.mongodb.mongodb_shell: + eval: "sh.status()" + mongo_cmd: "{{ mongodb_shell | default(omit) }}" + register: mongodb_status + retries: 6 + delay: 10 + + - name: Write MongoDB replicaset status + ansible.builtin.copy: + dest: "{{ mongodb_cluster_state_zero }}" + content: "{{ _content | to_nice_yaml(indent=2) }}" + mode: 0644 + vars: + _status: "{{ mongodb_status.transformed_output.value }}" + _content: "{{ _status | nephelaiio.plugins.drop_attributes(['databases', 'shardingVersion']) }}" + + +- name: Reconfigure cluster with ip addresses + import_playbook: nephelaiio.mongodb.install + vars: + mongodb_hosts_manage: false + + +- name: Gather cluster facts + hosts: mongodb_mongos + become: true + tasks: + - name: Gather MongoDB existing replica set members + community.mongodb.mongodb_shell: + eval: "sh.status()" + mongo_cmd: "{{ mongodb_shell | default(omit) }}" + register: mongodb_status + retries: 6 + delay: 10 + + - name: Write MongoDB replicaset status + ansible.builtin.copy: + dest: "{{ mongodb_cluster_state_one }}" + content: "{{ _content | to_nice_yaml(indent=2) }}" + mode: 0644 + vars: + _status: "{{ mongodb_status.transformed_output.value }}" + _content: "{{ _status | nephelaiio.plugins.drop_attributes(['databases', 'shardingVersion']) }}" + + +- name: Reconfigure cluster with hostnames + import_playbook: nephelaiio.mongodb.install + vars: + mongodb_hosts_manage: true + + +- name: Gather cluster facts + hosts: mongodb_mongos + become: true + tasks: + - name: Gather MongoDB existing replica set members + community.mongodb.mongodb_shell: + eval: "sh.status()" + mongo_cmd: "{{ mongodb_shell | default(omit) }}" + register: mongodb_status + retries: 6 + delay: 10 + + - name: Write MongoDB replicaset status + ansible.builtin.copy: + dest: "{{ mongodb_cluster_state_two }}" + content: "{{ _content | to_nice_yaml(indent=2) }}" + mode: 0644 + vars: + _status: "{{ mongodb_status.transformed_output.value }}" + _content: "{{ _status | nephelaiio.plugins.drop_attributes(['databases', 'shardingVersion']) }}" diff --git a/molecule/hostfile/verify.yml b/molecule/hostfile/verify.yml new file mode 100644 index 0000000..43a97d2 --- /dev/null +++ b/molecule/hostfile/verify.yml @@ -0,0 +1,11 @@ +--- +- name: Verify shard registration + hosts: mongodb_mongos + tasks: + - name: Verify cluster ip reconfig state + ansible.builtin.command: | + diff {{ mongodb_cluster_state_zero }} {{ mongodb_cluster_state_one}} + + - name: Verify cluster hostname reconfig state + ansible.builtin.command: | + diff {{ mongodb_cluster_state_one }} {{ mongodb_cluster_state_two}} diff --git a/roles.yml b/roles.yml index c38388d..e4581a8 100644 --- a/roles.yml +++ b/roles.yml @@ -12,7 +12,7 @@ roles: scm: git - name: mongodb src: https://github.com/wpnops/ansible-role-mongodb.git - version: 0.1.17 + version: 0.1.21 scm: git - name: update src: https://github.com/robertdebock/ansible-role-update.git