diff --git a/meta/main.yml b/meta/main.yml index 7fd7633482aa0dc05780fff1ff4be37751f8e5d0..1ae38a22ce153408d36fb7c233a2723649987cea 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,4 +1,15 @@ --- - +galaxy_info: + role_name: commonkeys + author: Jürgen Haas + description: Exchange public keys of all hosts with all others + company: LakeDrops + license: MIT + min_ansible_version: 2.5.0 + platforms: + - name: Ubuntu + versions: + - 16 + - 18 dependencies: - { role: common, when: ignore_these_tasks is defined } diff --git a/tasks/admin_keys.yml b/tasks/admin_keys.yml index 637662e741799ad980178a59e51b18643c3381c6..28680793eec27abb2f8c713850c730cd27cf98d1 100644 --- a/tasks/admin_keys.yml +++ b/tasks/admin_keys.yml @@ -4,14 +4,14 @@ - block: - name: "Read public key of admin user" - shell: cat /home/{{ username }}/.ssh/id_rsa.pub + command: 'cat /home/{{ username }}/.ssh/id_rsa.pub' register: pubkey - name: "Distribute public key of admin user" authorized_key: - user='{{ username }}' - key="{{ hostvars[item].pubkey.stdout }} {{ item }}" - path='/home/{{ username }}/.ssh/fresh_auth_keys_tunnel_{{ item }}' + user: '{{ username }}' + key: '{{ hostvars[item].pubkey.stdout }} {{ item }}' + path: '/home/{{ username }}/.ssh/fresh_auth_keys_tunnel_{{ item }}' with_items: '{{ groups.all }}' when: item != "localhost" and inventory_hostname != "localhost" and hostvars[item].pubkey is defined diff --git a/tasks/main.yml b/tasks/main.yml index 00cc362237d64b1d0dbb7482f1e8990c027c6572..0975626e2767afedcf2c5d5725d9703ece9e9b08 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,33 +1,37 @@ --- # file: roles/commonkeys/tasks/main.yml -- name: "Common Keys Role" - set_fact: role_commonkeys_started=true - tags: 'always' +- name: Common Keys Role + set_fact: + role_commonkeys_started: yes + tags: + - always - block: - - name: "Reset all hosts" - include_tasks: reset.yml - with_items: '{{ groups.all }}' - loop_control: - loop_var: hostname - when: hostname != "localhost" and inventory_hostname != "localhost" + - name: Reset all hosts + include_tasks: reset.yml + with_items: '{{ groups.all }}' + loop_control: + loop_var: hostname + when: hostname != "localhost" and inventory_hostname != "localhost" - - name: "Admin keys" - include_tasks: admin_keys.yml - loop_control: - loop_var: username - with_items: '{{ admins }}' - tags: 'Keys' + - name: Admin keys + include_tasks: admin_keys.yml + loop_control: + loop_var: username + with_items: '{{ admins }}' + tags: + - Keys - - name: "User keys" - include_tasks: user_keys.yml - with_flattened: - - '{{ admins }}' - - '{{ jailusers }}' - loop_control: - loop_var: username - tags: 'Keys' + - name: User keys + include_tasks: user_keys.yml + with_flattened: + - '{{ admins }}' + - '{{ jailusers }}' + loop_control: + loop_var: username + tags: + - Keys - when: '"commonkeys" not in excluded_roles' + when: not excluded_roles or "commonkeys" not in excluded_roles diff --git a/tasks/reset.yml b/tasks/reset.yml index 5f8c2930afb9c6742e20a7dd41e6414f41ccc7ff..bf86ab59aa7d98d0826d81d946cd40bcd91f3c85 100644 --- a/tasks/reset.yml +++ b/tasks/reset.yml @@ -2,19 +2,19 @@ # file: roles/commonkeys/tasks/reset.yml - name: "Remove previous hostname from known_hosts" - become: no known_hosts: - name="{{ hostname }}" - state="absent" + name: '{{ hostname }}' + state: 'absent' + become: no - name: "Remove previous ip from known_hosts" - become: no known_hosts: - name="{{ hostvars[hostname]['static_ipv4']|default(hostvars[hostname]['ansible_default_ipv4']['address']) }}" - state="absent" + name: "{{ hostvars[hostname]['static_ipv4']|default(hostvars[hostname]['ansible_default_ipv4']['address']) }}" + state: 'absent' + become: no - name: "Include all hosts into /etc/hosts" lineinfile: - dest=/etc/hosts - regexp="^{{ hostvars[hostname]['static_ipv4']|default(hostvars[hostname]['ansible_default_ipv4']['address']) }} " - line="{{ hostvars[hostname]['static_ipv4']|default(hostvars[hostname]['ansible_default_ipv4']['address']) }} {{ hostname }}" + dest: '/etc/hosts' + regexp: "^{{ hostvars[hostname]['static_ipv4']|default(hostvars[hostname]['ansible_default_ipv4']['address']) }} " + line: "{{ hostvars[hostname]['static_ipv4']|default(hostvars[hostname]['ansible_default_ipv4']['address']) }} {{ hostname }}" diff --git a/tasks/user_keys.yml b/tasks/user_keys.yml index f3b68c02d1d722fe3abedf547fddef77dccc2ca4..4946f450435c47541e6a8bb0f4aafd72b48248f3 100644 --- a/tasks/user_keys.yml +++ b/tasks/user_keys.yml @@ -5,41 +5,45 @@ - name: "Keys | Remove the fresh auth file in case it does already exist" file: - path=/home/{{ username }}/.ssh/auth_keys_fresh - state=absent + path: '/home/{{ username }}/.ssh/auth_keys_fresh' + state: 'absent' - name: "Keys | Install Public Keys For Desktop-To-Server Communication in a fresh file" authorized_key: - user={{ username }} - key="{{ lookup('file', inventory_dir + '/files/keys/' + username + '.d2s.pub') }}" - path=/home/{{ username }}/.ssh/fresh_auth_keys_{{ username }} - key_options={{ users[username]['ssh_key_options']|default(omit) }} + user: '{{ username }}' + key: "{{ lookup('file', inventory_dir + '/files/keys/' + username + '.d2s.pub') }}" + path: '/home/{{ username }}/.ssh/fresh_auth_keys_{{ username }}' + key_options: "{{ users[username]['ssh_key_options']|default(omit) }}" - name: "Keys | Merge all public keys" - shell: cat /home/{{ username }}/.ssh/fresh_auth_keys* > /home/{{ username }}/.ssh/auth_keys_fresh + shell: 'cat /home/{{ username }}/.ssh/fresh_auth_keys* > /home/{{ username }}/.ssh/auth_keys_fresh' - name: "Keys | Remove temp files" - shell: rm /home/{{ username }}/.ssh/fresh_auth_keys_* + file: + path: '{{ item }}' + state: 'absent' + with_fileglob: + - '/home/{{ username }}/.ssh/fresh_auth_keys_*' - name: "Keys | Set ownership of authorized key file" file: - path="/home/{{ username }}/.ssh/auth_keys_fresh" - owner="{{ username }}" - group="root" + path: '/home/{{ username }}/.ssh/auth_keys_fresh' + owner: '{{ username }}' + group: 'root' - name: "Keys | Set permission for authorized key file" file: - path="/home/{{ username }}/.ssh/auth_keys_fresh" - mode='600' + path: '/home/{{ username }}/.ssh/auth_keys_fresh' + mode: '600' - name: "Keys | Make sure the authorized_keys file exists" file: - name=/home/{{ username }}/.ssh/authorized_keys - state=touch + name: '/home/{{ username }}/.ssh/authorized_keys' + state: 'touch' - name: "Keys | Move the fresh auth file to replace the old one" - shell: rm /home/{{ username }}/.ssh/authorized_keys && mv /home/{{ username }}/.ssh/auth_keys_fresh /home/{{ username }}/.ssh/authorized_keys + shell: 'rm /home/{{ username }}/.ssh/authorized_keys && mv /home/{{ username }}/.ssh/auth_keys_fresh /home/{{ username }}/.ssh/authorized_keys' args: - executable: /bin/bash + executable: '/bin/bash' tags: 'Keys'