Clean final newline when distributing SSH keys

When a pattern containing newlines is given to grep, it treats each
line as a different pattern, and ORs these patterns together. The
empty string always matches, therefore grep always returns a
successful match.

Change-Id: I881c90979995e060d24988438a710376e54331b8
Closes-Bug: #1615624
This commit is contained in:
Paulo Matias 2016-08-22 10:05:20 -03:00
parent e13a00ce54
commit 354147b7c7

View File

@ -19,7 +19,7 @@ fi
{% for item in groups['nova_compute'] %}
{% if hostvars[item]['nova_pubkey'] is defined %}
KEY="{{ hostvars[item]['nova_pubkey'] | b64decode }}"
KEY="{{ hostvars[item]['nova_pubkey'] | b64decode | trim }}"
if ! grep -q -w "${KEY}" "${USER_HOME}/.ssh/authorized_keys"; then
echo "${KEY}" | tee -a "${USER_HOME}/.ssh/authorized_keys"
EXIT_CODE=3