ansible-infra/roles/ansible_pull/tasks/main.yaml
June 1157c98ff5
ansible-pull(role): make successful run timestamp exporter work
The successful run timestamp exporter didn't work, because the
ansible-pull user wouldn't necessarily have the necessary permissions
and because the command wouldn't properly work.
Move the timestamp export as well as the reboot to separate services,
which always run as root, to ensure these operations work and to have a
clean setup using systemd services.
Also move the successful run timestamp exporter to a custom script to
have it work properly.
2026-11-04 17:28:03 +01:00

109 lines
2.7 KiB
YAML

- name: ensure dependencies are installed
block:
- name: ensure apt dependencies are installed
ansible.builtin.apt:
name:
- python3-pip
- virtualenv
- git
state: present
become: true
- name: ensure SOPS is installed
ansible.builtin.include_role:
name: community.sops.install
# https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-and-upgrading-ansible-with-pip
# https://www.redhat.com/en/blog/python-venv-ansible
- name: ensure Ansible installation exists
ansible.builtin.pip:
name:
- ansible
- jmespath
state: present
virtualenv: /usr/local/lib/ansible_pull_venv
become: true
- name: ensure helper script installations exist
ansible.builtin.copy:
src: "{{ item }}.sh"
dest: "/usr/local/sbin/{{ item }}"
owner: root
group: root
mode: "0755"
become: true
loop:
- ansible-pull-successful-run-timestamp-exporter
- name: ensure ansible-pull-failure-notify script installation exists
ansible.builtin.template:
src: ansible-pull-failure-notify.sh.j2
dest: /usr/local/sbin/ansible-pull-failure-notify.sh
owner: root
group: root
mode: "0755"
become: true
- name: ensure secrets directory exists
ansible.builtin.file:
path: /etc/ansible_pull_secrets
state: directory
mode: "0750"
owner: root
group: "{{ ansible_pull__user }}"
become: true
- name: ensure age private key is deployed
ansible.builtin.copy:
content: "{{ ansible_pull__age_private_key }}"
dest: /etc/ansible_pull_secrets/age_private_key
mode: "0640"
owner: root
group: "{{ ansible_pull__user }}"
become: true
- name: ensure templated systemd services exists
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "/etc/systemd/system/{{ item }}"
owner: root
group: root
mode: "0644"
become: true
loop:
- ansible-pull.service
- ansible-pull-failure-notify.service
notify:
- systemd daemon reload
- name: ensure systemd services exists
ansible.builtin.copy:
src: "{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
owner: root
group: root
mode: "0644"
become: true
loop:
- ansible-pull-reboot.service
- ansible-pull-successful-run-timestamp-exporter.service
notify:
- systemd daemon reload
- name: ensure systemd timer exists
ansible.builtin.template:
src: ansible-pull.timer.j2
dest: /etc/systemd/system/ansible-pull.timer
owner: root
group: root
mode: "0644"
become: true
notify:
- systemd daemon reload
- name: ensure systemd timer is started and enabled
ansible.builtin.systemd_service:
name: ansible-pull.timer
state: started
enabled: true
become: true