diff --git a/CHANGELOG.md b/CHANGELOG.md index e7b441ed0c..322b31fe5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ### HEAD +* Improve support for adding public SSH keys ([#1344](https://github.com/roots/trellis/pull/1344)) * Fix #1319 - Improve how ssh_args are loaded ([#1337](https://github.com/roots/trellis/pull/1337)) * Fix #1331 - Improve passlib instructions([#1336](https://github.com/roots/trellis/pull/1336)) diff --git a/lib/trellis/utils/output.py b/lib/trellis/utils/output.py index ca4eb22728..33dbc4b55a 100644 --- a/lib/trellis/utils/output.py +++ b/lib/trellis/utils/output.py @@ -55,7 +55,7 @@ def replace_item_with_key(obj, result): ) if should_replace: - if 'key' in result._result[item]: + if type(result._result[item]) is dict and 'key' in result._result[item]: result._result[item] = result._result[item]['key'] elif type(result._result[item]) is dict: subitem = '_ansible_item_label' if '_ansible_item_label' in result._result[item] else 'item' diff --git a/public_keys/.gitkeep b/public_keys/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/roles/users/tasks/main.yml b/roles/users/tasks/main.yml index acfcd74838..09b84830df 100644 --- a/roles/users/tasks/main.yml +++ b/roles/users/tasks/main.yml @@ -49,7 +49,7 @@ validate: "/usr/sbin/visudo -cf %s" when: web_sudoers[0] is defined -- name: Add SSH keys +- name: Add user SSH keys authorized_key: user: "{{ item.0.name }}" key: "{{ item.1 }}" @@ -57,6 +57,12 @@ - "{{ users | default([]) }}" - keys +- name: Add deploy SSH keys + authorized_key: + user: "{{ web_user }}" + key: "{{ lookup('file', item) }}" + with_fileglob: 'public_keys/*.pub' + - name: Check whether Ansible can connect as admin_user command: ansible {{ inventory_hostname }} -m ping -u {{ admin_user }} {{ cli_options | default('') }} delegate_to: localhost