Files
12de509741a4b93193175d5db0bca595aaad6de2
openstack-ansible-os_nova /templates /nova-key-insert.sh.j2

32 lines
1017 B
Plaintext
Raw Normal View History

# Running the script:
# * The script will exit 99 if the home folder for the user set by
# "nova_system_user_name" is not found.
# * If the script adds a key to the authorized keys file it will exit 3.
# * If the script takes no action it will exit 0.
set -ex
EXIT_CODE=0
USER_HOME="$(getent passwd {{ nova_system_user_name }} | awk -F':' '{print 6ドル}')"
[[ -d "${USER_HOME}" ]] || exit 99
if [[ ! -f "${USER_HOME}/.ssh/authorized_keys" ]]; then
touch "${USER_HOME}/.ssh/authorized_keys"
chown {{ nova_system_user_name }}:{{ nova_system_group_name }} "${USER_HOME}/.ssh/authorized_keys"
chmod 0600 "${USER_HOME}/.ssh/authorized_keys"
fi
{% for item in groups['nova_compute'] %}
{% if hostvars[item]['nova_pubkey'] is defined %}
echo "${KEY}" | tee -a "${USER_HOME}/.ssh/authorized_keys"
EXIT_CODE=3
fi
{% endif %}
{% endfor %}
exit "${EXIT_CODE}"