From 166ee3d20c9f058dede5343bbd152ef670903bee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rados=C5=82aw=20Piliszek?= <radoslaw.piliszek@gmail.com>
Date: Mon, 29 Aug 2022 12:12:43 +0000
Subject: [PATCH] [CI] Do not use the kolla user

The kolla user is not obligatory and the docs default to keeping
using the existing users.

Needed-By: https://review.opendev.org/c/openstack/ansible-collection-kolla/+/854985
Depends-On: https://review.opendev.org/c/openstack/kolla-ansible/+/855071
Change-Id: I917f493d395cc7efcbf95bc55af8191d70ec3edb
---
 tests/run.yml                     | 23 +----------------------
 tests/setup_gate.sh               |  2 +-
 tests/templates/ceph-inventory.j2 |  2 +-
 tests/templates/inventory.j2      | 22 +++++++++++-----------
 4 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/tests/run.yml b/tests/run.yml
index 9233774034..c4cad60fa0 100644
--- a/tests/run.yml
+++ b/tests/run.yml
@@ -283,30 +283,9 @@
     - name: generate passwords
       command: "{{ kolla_ansible_venv_path }}/bin/kolla-genpwd"
 
-    - name: slurp kolla passwords
-      slurp:
-        src: /etc/kolla/passwords.yml
-      register: passwords_yml
-
-    - name: write out kolla SSH private key
-      copy:
-        content: "{{ (passwords_yml.content | b64decode | from_yaml).kolla_ssh_key.private_key }}"
-        dest: ~/.ssh/id_rsa_kolla
-        mode: 0600
-
-    - name: authorise kolla public key for zuul user
-      authorized_key:
-        user: "{{ ansible_env.USER }}"
-        key: "{{ (passwords_yml.content | b64decode | from_yaml).kolla_ssh_key.public_key }}"
-      # Delegate to each host in turn. If more tasks require execution on all
-      # hosts in future, break out into a separate play.
-      with_inventory_hostnames:
-        - all
-      delegate_to: "{{ item }}"
-
     - name: Record the running state of the environment as seen by the setup module
       shell:
-        cmd: "{{ kolla_ansible_venv_path }}/bin/ansible all -i {{ kolla_inventory_path }} -e ansible_user={{ ansible_user }} -m setup > /tmp/logs/ansible/initial-setup"
+        cmd: "{{ kolla_ansible_venv_path }}/bin/ansible all -i {{ kolla_inventory_path }} -m setup > /tmp/logs/ansible/initial-setup"
 
     - name: Set facts for actions
       set_fact:
diff --git a/tests/setup_gate.sh b/tests/setup_gate.sh
index 75cf3934d7..5886c61d03 100755
--- a/tests/setup_gate.sh
+++ b/tests/setup_gate.sh
@@ -143,7 +143,7 @@ setup_openstack_clients
 RAW_INVENTORY=/etc/kolla/inventory
 
 source $KOLLA_ANSIBLE_VENV_PATH/bin/activate
-kolla-ansible -i ${RAW_INVENTORY} -e ansible_user=$USER -vvv bootstrap-servers &> /tmp/logs/ansible/bootstrap-servers
+kolla-ansible -i ${RAW_INVENTORY} -vvv bootstrap-servers &> /tmp/logs/ansible/bootstrap-servers
 deactivate
 
 prepare_images
diff --git a/tests/templates/ceph-inventory.j2 b/tests/templates/ceph-inventory.j2
index b9f87dcb43..f005bfec5f 100644
--- a/tests/templates/ceph-inventory.j2
+++ b/tests/templates/ceph-inventory.j2
@@ -1,6 +1,6 @@
 [storage]
 {% for host in hostvars %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endfor %}
 
 # Ceph-Ansible hosts
diff --git a/tests/templates/inventory.j2 b/tests/templates/inventory.j2
index 28cf537785..bd8b50ca8f 100644
--- a/tests/templates/inventory.j2
+++ b/tests/templates/inventory.j2
@@ -8,15 +8,15 @@
 [control]
 {% if scenario == 'masakari' %}
 {% for host in hostvars if host in ['primary'] %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endfor %}
 {% elif scenario == 'monasca' %}
 {% for host in hostvars if host in ['primary', 'secondary1', 'secondary2'] %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endfor %}
 {% else %}
 {% for host in hostvars %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endfor %}
 {% endif %}
 
@@ -32,40 +32,40 @@ control
 [compute]
 {% if scenario == 'masakari' %}
 {% for host in hostvars if host in ['ternary1', 'ternary2'] %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endfor %}
 {% else %}
 {% for host in hostvars %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endfor %}
 {% endif %}
 
 [storage]
 {% for host in hostvars %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endfor %}
 
 [monitoring]
 {% if scenario == 'monasca' %}
 {% for host in hostvars if host in ['secondary3', 'secondary4', 'secondary5'] %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endfor %}
 {% else %}
 {% for host in hostvars %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endfor %}
 {% endif %}
 
 [deployment]
 {% for host in hostvars %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endfor %}
 
 {% if scenario == 'cells' %}
 {% for host in hostvars %}
 {% set cell_name = 'cell' ~ loop.index %}
 [{{ cell_name }}]
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }} mariadb_shard_id={{ loop.index0 % 2 }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} mariadb_shard_id={{ loop.index0 % 2 }}
 
 [{{ cell_name }}:vars]
 nova_cell_name = {{ cell_name }}
@@ -139,7 +139,7 @@ control
 [hacluster]
 {% for host in hostvars %}
 {% if host in ['primary', 'secondary'] %}
-{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }} ansible_user=kolla ansible_ssh_private_key_file={{ ansible_env.HOME ~ '/.ssh/id_rsa_kolla' }}
+{{ host }} ansible_host={{ hostvars[host]['ansible_host'] }}
 {% endif %}
 {% endfor %}