Improve deployer UX by limiting failure output potential

This change will improve the deployer UX by ensuring that the log output does not show
failed tasks. While the potential for failed tasks should be rescued, and complete
successfully, the output confusing and could result in the operator taking unnecessary
debugging steps during a deployment. To ensure that the output is accurate and easy
to understand the playbook will now stat the required file and the needed blocks
will only execute when the appropriate conditions are met.

Change-Id: I0e69f44a6e06926a8987defa96c7ffac167ccdb5
Signed-off-by: Kevin Carter <kecarter@redhat.com>
This commit is contained in:
Kevin Carter 2020-03-25 11:18:26 -05:00
parent 8e0bb61135
commit 43aa2c6a44
No known key found for this signature in database
GPG Key ID: CE94BD890A47B20A
1 changed files with 59 additions and 44 deletions

View File

@ -87,59 +87,74 @@
ssh_key_file: "{{ ansible_home }}/.ssh/id_rsa"
become: true
- name: Stat key file
stat:
path: "{{ defined_user_private_key_file }}"
register: key_check
- name: Key block
run_once: true
when:
- user_public_key is undefined
- user_private_key is undefined
- user_private_key_file is undefined
block:
- name: Get local private key
slurp:
src: "{{ defined_user_private_key_file }}"
register: private_key_get
become: true
- name: Read key block
run_once: true
when:
- key_check.stat.exists | bool
block:
- name: Get local private key
slurp:
src: "{{ defined_user_private_key_file }}"
register: private_key_get
become: true
- name: Get local public key
slurp:
src: "{{ defined_user_private_key_file }}.pub"
register: public_key_get
become: true
- name: Get local public key
slurp:
src: "{{ defined_user_private_key_file }}.pub"
register: public_key_get
become: true
- name: Set key facts
set_fact:
user_public_key: "{{ public_key_get['content'] | b64decode }}"
user_private_key: "{{ private_key_get['content'] | b64decode }}"
user_private_key_file: "{{ defined_user_private_key_file }}"
rescue:
- name: Get local private key
slurp:
src: "{{ ansible_home }}/.ssh/id_rsa"
register: private_key_get
become: true
- name: Set key facts
set_fact:
user_public_key: "{{ public_key_get['content'] | b64decode }}"
user_private_key: "{{ private_key_get['content'] | b64decode }}"
user_private_key_file: "{{ defined_user_private_key_file }}"
- name: Get local public key
slurp:
src: "{{ ansible_home }}/.ssh/id_rsa.pub"
register: public_key_get
become: true
- name: Read and create key block
run_once: true
when:
- not (key_check.stat.exists | bool)
block:
- name: Get local private key
slurp:
src: "{{ ansible_home }}/.ssh/id_rsa"
register: private_key_get
become: true
- name: Set key facts
set_fact:
user_public_key: "{{ public_key_get['content'] | b64decode }}"
user_private_key: "{{ private_key_get['content'] | b64decode }}"
- name: Get local public key
slurp:
src: "{{ ansible_home }}/.ssh/id_rsa.pub"
register: public_key_get
become: true
- name: Write tripleo private key
copy:
content: "{{ user_private_key }}"
dest: "{{ defined_user_private_key_file }}"
mode: "0600"
- name: Write tripleo private key
copy:
content: "{{ private_key_get['content'] | b64decode }}"
dest: "{{ defined_user_private_key_file }}"
mode: "0600"
- name: Write tripleo public key
copy:
content: "{{ user_public_key }}"
dest: "{{ defined_user_private_key_file }}.pub"
mode: "0640"
- name: Write tripleo public key
copy:
content: "{{ public_key_get['content'] | b64decode }}"
dest: "{{ defined_user_private_key_file }}.pub"
mode: "0640"
- name: Set key file fact
set_fact:
user_private_key_file: "{{ defined_user_private_key_file }}"
- name: Set key file fact
set_fact:
user_public_key: "{{ public_key_get['content'] | b64decode }}"
user_private_key: "{{ private_key_get['content'] | b64decode }}"
user_private_key_file: "{{ defined_user_private_key_file }}"
- name: Ensure user can ssh to localhost
authorized_key: