/
/
/
This repo is destined for my server automations and setup.
1---
2# ============================================================================
3# Automation access - authorized keys for the ansible user
4# ============================================================================
5#
6# Adds the public keys in ansible_user_authorized_keys (group_vars/all) to
7# the ansible user on every host, so automation such as Semaphore can run
8# the playbooks. Keys are only added; nothing existing is removed.
9#
10# USAGE:
11# ansible-playbook access.yml
12# ============================================================================
13
14- name: Authorize automation keys for the ansible user
15 hosts: all
16 gather_facts: false
17 become: false # the user manages its own authorized_keys
18 ignore_unreachable: true
19
20 tasks:
21 - name: Add the automation keys
22 ansible.posix.authorized_key:
23 user: "{{ ansible_user }}"
24 key: "{{ item.key }}"
25 comment: "{{ item.comment | default(omit) }}"
26 state: present
27 loop: "{{ ansible_user_authorized_keys | default([]) }}"
28 loop_control:
29 label: "{{ item.comment | default(item.key[:40]) }}"
30