Added ansible-update script, service and timer (#2)

Reviewed-on: #2
This commit is contained in:
Jayne Passmore 2025-07-24 17:20:15 -05:00
parent fc76d0b802
commit c9c7253dc1
9 changed files with 55 additions and 8 deletions

View file

@ -1,7 +1,7 @@
role-ansible-update role-ansible-update
========= =========
A brief description of the role goes here. This role sets up a systemd service/timer and bash script to run ansible daily - staggers hosts hourly based on ansibleid
Requirements Requirements
------------ ------------
@ -23,8 +23,8 @@ Example Playbook Template
Playbook creation should be handled by playbook-builder. To include role in a playbook, add one of these lines (changing version/branch as needed) to the template with other core entries: Playbook creation should be handled by playbook-builder. To include role in a playbook, add one of these lines (changing version/branch as needed) to the template with other core entries:
role:mount:v1.0:core,mount role:ansible-update:v1.0:core,ansible
role:mount:testing:core,mount role:ansible-update:testing:core,ansible
License License
------- -------

View file

@ -1,3 +1,3 @@
#SPDX-License-Identifier: MIT-0 #SPDX-License-Identifier: MIT-0
--- ---
# defaults file for ${REPO_NAME} # defaults file for ansible-update

View file

@ -0,0 +1,10 @@
[Unit]
Description=Runs ansible playbook
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/bin/bash /scripts/ansible-update.sh
[Install]
WantedBy=multi-user.target

4
files/ansible-update.sh Normal file
View file

@ -0,0 +1,4 @@
#! /bin/bash
cd /ansible
/bin/bash build_ansible.sh

View file

@ -1,3 +1,3 @@
#SPDX-License-Identifier: MIT-0 #SPDX-License-Identifier: MIT-0
--- ---
# handlers file for ${REPO_NAME} # handlers file for ansible-update

View file

@ -1,3 +1,27 @@
#SPDX-License-Identifier: MIT-0 #SPDX-License-Identifier: MIT-0
--- ---
# tasks file for ${REPO_NAME} # tasks file for ansible-update
- name: deploy ansible update script
ansible.builtin.copy:
src: files/ansible-update.sh
dest: /scripts/ansible-update.sh
mode: '0754'
- name: deploy ansible update service
ansible.builtin.copy:
src: files/ansible-update.service
dest: /usr/lib/systemd/system/ansible-update.service
mode: '0644'
- name: deploy ansible update timer
ansible.builtin.template:
src: templates/ansible-update.timer
dest: /usr/lib/systemd/system/ansible-update.timer
mode: '0644'
- name: ensure ansible update script is running
service:
name: ansible-update.timer
state: started
daemon_reload: true
enabled: yes

View file

@ -0,0 +1,9 @@
[Unit]
Description=Runs run ansible playbook once per day (hour is determined based on ansible id)
[Timer]
OnCalendar=*-*-* {{ansible_machine_id | int(base=16) % 24}}:00:00
Unit=ansible-update.service
[Install]
WantedBy=multi-user.target

View file

@ -3,4 +3,4 @@
- hosts: localhost - hosts: localhost
remote_user: root remote_user: root
roles: roles:
- ${REPO_NAME} - ansible-update

View file

@ -1,3 +1,3 @@
#SPDX-License-Identifier: MIT-0 #SPDX-License-Identifier: MIT-0
--- ---
# vars file for ${REPO_NAME} # vars file for ansible-update