timeout=30
+filter_plugins = ./filter_plugins
+
[ssh_connection]
pipelining = True
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s
--- /dev/null
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+from ansible import errors
+
+
+def user_ssh_keys(data, db):
+ try:
+ ssh_keys = []
+ for user in data:
+ try:
+ for key in db[user]['ssh']:
+ ssh_keys.append(key)
+ except KeyError:
+ pass
+
+ return ssh_keys
+ except Exception as e:
+ raise errors.AnsibleFilterError("user_ssh_keys(): %s" % str(e))
+
+
+class FilterModule(object):
+
+ ''' extract values form users db '''
+ filter_map = {
+ 'user_ssh_keys': user_ssh_keys,
+ }
+
+ def filters(self):
+ return self.filter_map
---
-ssh_root_users:
+ssh_users_root:
- equinox
- nicoo
/etc/dropbear/authorized_keys:
content: |-
- {% for key in ssh_keys_root %}
+ {% for key in ssh_users_root | user_ssh_keys(users) %}
{{ key }}
{% endfor %}
## SSH keys for root, default to NOC's
ssh_users_root: "{{ user_groups.noc }}"
-## TODO: make this a filter_plugin...
-ssh_keys_root: "{{ ssh_users_root | map('extract', users) | map(attribute='ssh') | flatten | list }}"
-
-## TODO: not used at the moment?
-noc_groups:
- - adm
- - sudo
---
-ssh_keys_tuergit: "{{ ssh_keys_root }}"
+ssh_users_tuergit: "{{ user_groups.noc }}"
openwrt_arch: x86
openwrt_target: geode
/etc/ssh/authorized_keys.d/root:
content: |-
- {% for key in ssh_keys_root %}
+ {% for key in ssh_users_root | user_ssh_keys(users) %}
{{ key }}
{% endfor %}
/etc/ssh/authorized_keys.d/tuergit:
content: |-
- {% for key in ssh_keys_tuergit %}
+ {% for key in ssh_users_tuergit | user_ssh_keys(users) %}
{{ key }}
{% endfor %}
- name: Set authorized keys for root user
authorized_key:
user: root
- key: "{{ ssh_keys_root | join('\n') }}"
+ key: "{{ ssh_users_root | user_ssh_keys(users) | join('\n') }}"
exclusive: yes
- name: disable apt suggests and recommends
user: root
manage_dir: no
path: "{{ preseed_tmpdir }}/authorized_keys"
- key: "{{ ssh_keys_root | join('\n') }}"
+ key: "{{ ssh_users_root | user_ssh_keys(users) | join('\n') }}"
- name: Inject files into initramfs
shell: cpio -H newc -o | gzip -9 >> 'initrd.preseed.gz'
- import_role:
name: preseed
vars:
- ssh_keys_root: "{{ hostvars[hostname].ssh_keys_root }}"
+ ssh_users_root: "{{ hostvars[hostname].ssh_users_root }}"
install_interface: enp1s1
preseed_tmpdir: "{{ tmpdir.stdout }}"