Skip to content

Commit b854458

Browse files
authored
Disable name_prefix validation on teardown and enable check for misconfigured SSH key permissions
* Do not validate name_prefix when running a teardown, the user may have reasons for wanting to purge an arbitrary namespace * Validate SSH Private Key File permissions to handle edge case where a user has misconfigured their ssh dir and Ansible will refuse to connect Signed-off-by: Daniel Chaffelson <chaffelson@gmail.com>
1 parent 6326270 commit b854458

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

roles/cloudera_deploy/tasks/init.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@
184184

185185
# Validate Name Prefix
186186
- name: Check supplied Namespace (Azure)
187-
when: globals.infra_type == 'azure'
187+
when:
188+
- globals.infra_type == 'azure'
189+
- "'teardown' not in {{ ansible_run_tags }}"
188190
ansible.builtin.assert:
189191
that:
190192
- globals.name_prefix | length > 1
@@ -194,7 +196,9 @@
194196
quiet: yes
195197

196198
- name: Check supplied Namespace
197-
when: globals.infra_type != 'azure'
199+
when:
200+
- globals.infra_type != 'azure'
201+
- "'teardown' not in {{ ansible_run_tags }}"
198202
ansible.builtin.assert:
199203
that:
200204
- globals.name_prefix | length > 1
@@ -246,6 +250,23 @@
246250
ssh:
247251
public_key_text: "{{ lookup('file', globals.ssh.public_key_file ) | default(omit) }}"
248252

253+
- name: Validate SSH Private Key File has acceptable permissions
254+
when: globals.ssh.private_key_file is defined
255+
block:
256+
- name: Get information for SSH Private Key File
257+
ansible.builtin.stat:
258+
path: "{{ globals.ssh.private_key_file }}"
259+
register: __private_key_file_stat
260+
261+
- name: Assert that SSH Private Key has valid permissions
262+
ansible.builtin.assert:
263+
that:
264+
- __private_key_file_stat.stat.mode == '0400' or __private_key_file_stat.stat.mode == '0600'
265+
fail_msg:
266+
- "SSH Private Key at {{ __private_key_file_stat.stat.path }} has invalid permissions"
267+
- "Permissions are {{ __private_key_file_stat.stat.mode }}"
268+
- "Permissions should be 0400 or 0600"
269+
249270
# Read in Dynamic Inventory
250271
- name: Seek Inventory Template in Definition Path
251272
register: __di_template_stat

0 commit comments

Comments
 (0)