From 572ff2f8dc848453a6781731fb400dc5c9231fad Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Thu, 12 Jan 2023 10:27:47 +0000
Subject: [PATCH] Fix deploy/genconfig in check mode

Previously, when running one of the following commands:

  kolla-ansible deploy --check
  kolla-ansible genconfig --check

deployment or configuration generation fails for various reasons.

MariaDB fails to lookup the existing cluster.

Keystone fails to generate cron config.

Nova-cell fails to get the cell settings.

Closes-Bug: #2002661
Change-Id: I5e765f498ae86d213d0a4379ca5d473db1499962
---
 ansible/roles/keystone/tasks/config.yml                  | 1 +
 ansible/roles/mariadb/tasks/lookup_cluster.yml           | 1 +
 ansible/roles/nova-cell/tasks/get_cell_settings.yml      | 1 +
 ansible/roles/nova-cell/tasks/wait_discover_computes.yml | 1 +
 releasenotes/notes/fix-check-mode-1f37ab5507c98954.yaml  | 5 +++++
 5 files changed, 9 insertions(+)
 create mode 100644 releasenotes/notes/fix-check-mode-1f37ab5507c98954.yaml

diff --git a/ansible/roles/keystone/tasks/config.yml b/ansible/roles/keystone/tasks/config.yml
index 53c1d9cfc3..432f7991e1 100644
--- a/ansible/roles/keystone/tasks/config.yml
+++ b/ansible/roles/keystone/tasks/config.yml
@@ -199,6 +199,7 @@
     -i {{ groups['keystone'].index(inventory_hostname) }}
     -n {{ (groups['keystone'] | length) }}
   changed_when: false
+  check_mode: false
   register: cron_jobs_json
   delegate_to: localhost
 
diff --git a/ansible/roles/mariadb/tasks/lookup_cluster.yml b/ansible/roles/mariadb/tasks/lookup_cluster.yml
index 39172abc4c..409491776b 100644
--- a/ansible/roles/mariadb/tasks/lookup_cluster.yml
+++ b/ansible/roles/mariadb/tasks/lookup_cluster.yml
@@ -50,6 +50,7 @@
             --silent --skip-column-names
             -e 'SHOW STATUS LIKE "wsrep_local_state_comment"'
           changed_when: false
+          check_mode: false
           register: check_mariadb_sync_status
           no_log: true
 
diff --git a/ansible/roles/nova-cell/tasks/get_cell_settings.yml b/ansible/roles/nova-cell/tasks/get_cell_settings.yml
index 120b515ca1..b1cac0cb47 100644
--- a/ansible/roles/nova-cell/tasks/get_cell_settings.yml
+++ b/ansible/roles/nova-cell/tasks/get_cell_settings.yml
@@ -18,6 +18,7 @@
   changed_when: false
   failed_when:
     - existing_cells_list.rc != 0
+  check_mode: false
 
 - name: Extract current cell settings from list
   vars:
diff --git a/ansible/roles/nova-cell/tasks/wait_discover_computes.yml b/ansible/roles/nova-cell/tasks/wait_discover_computes.yml
index 1729eed390..640138bfe1 100644
--- a/ansible/roles/nova-cell/tasks/wait_discover_computes.yml
+++ b/ansible/roles/nova-cell/tasks/wait_discover_computes.yml
@@ -22,6 +22,7 @@
       register: nova_compute_services
       changed_when: false
       failed_when: false
+      check_mode: false
       retries: 20
       delay: 10
       until:
diff --git a/releasenotes/notes/fix-check-mode-1f37ab5507c98954.yaml b/releasenotes/notes/fix-check-mode-1f37ab5507c98954.yaml
new file mode 100644
index 0000000000..0f91aecf46
--- /dev/null
+++ b/releasenotes/notes/fix-check-mode-1f37ab5507c98954.yaml
@@ -0,0 +1,5 @@
+---
+fixes:
+  - |
+    Fixes deployment when using Ansible check mode. `LP#2002661
+    <https://bugs.launchpad.net/kolla-ansible/+bug/2002661>`__