diff --git a/galaxy.yml b/galaxy.yml index eecb00f..1c346e3 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: nephelaiio name: mongodb -version: 0.0.14 +version: 0.0.15 readme: README.md authors: - Ted Cook diff --git a/molecule/restart/molecule.yml b/molecule/restart/molecule.yml index 8cd879c..0f57bef 100644 --- a/molecule/restart/molecule.yml +++ b/molecule/restart/molecule.yml @@ -124,7 +124,7 @@ provisioner: playbooks: prepare: ../common/prepare.yml converge: ../common/install.yml - side-effect: ../common/restart.yml + side_effect: ../common/restart.yml verify: ../common/verify.yml config_options: defaults: diff --git a/playbooks/restart.yml b/playbooks/restart.yml index 726a717..d941382 100644 --- a/playbooks/restart.yml +++ b/playbooks/restart.yml @@ -1,10 +1,12 @@ --- -- name: Restart mongod services +- name: Restart config services serial: 1 - hosts: - - "{{ mongodb_config | default('mongodb_config') }}" - - "{{ mongodb_shard1 | default('mongodb_shard1') }}" + hosts: "{{ mongodb_config | default('mongodb_config') }}" become: true + pre_tasks: + - name: Include collection variables + ansible.builtin.include_vars: + file: main.yml tasks: - name: Include mongos service tasks ansible.builtin.include_role: @@ -13,11 +15,46 @@ vars: mongos_service_state: restarted + - name: Wait for replica set to stabilize + community.mongodb.mongodb_status: + replica_set: "{{ mongos_replicaset_config_name | default('config') }}" + validate: minimal + poll: "{{ mongodb_reconfig_poll }}" + interval: "{{ mongodb_reconfig_interval }}" + + +- name: Restart shard1 services + serial: 1 + hosts: "{{ mongodb_shard1 | default('mongodb_shard1') }}" + become: true + pre_tasks: + - name: Include collection variables + ansible.builtin.include_vars: + file: main.yml + tasks: + - name: Include mongos service tasks + ansible.builtin.include_role: + name: nephelaiio.mongodb.mongodb + tasks_from: service + vars: + mongos_service_state: restarted + + - name: Wait for replica set to stabilize + community.mongodb.mongodb_status: + replica_set: "{{ mongos_replicaset_shard1_name | default('shard1') }}" + validate: minimal + poll: "{{ mongodb_reconfig_poll }}" + interval: "{{ mongodb_reconfig_interval }}" + - name: Restart mongos services hosts: "{{ mongodb_mongos | default('mongodb_mongos') }}" become: true serial: 1 + pre_tasks: + - name: Include collection variables + ansible.builtin.include_vars: + file: main.yml tasks: - name: Include mongos service tasks ansible.builtin.include_role: @@ -25,3 +62,10 @@ tasks_from: service vars: mongos_service_state: restarted + + - name: Check mongos cluster status + community.mongodb.mongodb_shell: + login_database: "admin" + eval: "sh.status()" + retries: "{{ mongodb_reconfig_poll }}" + delay: "{{ mongodb_reconfig_interval }}" diff --git a/playbooks/vars/main.yml b/playbooks/vars/main.yml index 7fa9598..34231df 100644 --- a/playbooks/vars/main.yml +++ b/playbooks/vars/main.yml @@ -3,3 +3,5 @@ mongodb_address_attrs: ['ansible_default_ipv4', 'address'] mongodb_port: '27017' mongos_service_name: 'mongos' mongodb_shell: 'mongosh' +mongodb_reconfig_poll: 6 +mongodb_reconfig_interval: 10 diff --git a/roles.yml b/roles.yml index 9d636b2..49a1e6c 100644 --- a/roles.yml +++ b/roles.yml @@ -10,3 +10,6 @@ roles: src: https://github.com/wpnops/ansible-role-mongodb.git version: 0.1.6 scm: git + - name: update + src: https://github.com/robertdebock/ansible-role-update.git + version: 3.1.7