Skip to content

Instantly share code, notes, and snippets.

@jaepetto
Created July 8, 2021 13:20
Show Gist options
  • Save jaepetto/433ac11d13cd2b693178ebe16c72bd70 to your computer and use it in GitHub Desktop.
Save jaepetto/433ac11d13cd2b693178ebe16c72bd70 to your computer and use it in GitHub Desktop.
Sample systemd timer unit to run ansible-pull every 30 minutes
[Unit]
Description=Runs ansible-pull to get common server configuration
Wants=ansiblePull.timer
[Service]
Type=oneshot
ExecStart=/usr/bin/ansible-pull -U https://github.com/<username>/<repo_name>.git --accept-host-key -i hosts --vault-password-file /root/.vault_password
[Install]
WantedBy=multi-user.target
[Unit]
Description=starts ansible-pull to get common server configuration
Requires=ansiblePull.service
[Timer]
Unit=ansiblePull.service
OnCalendar=*:0/30:00
[Install]
WantedBy=timers.target
---
- name: My task
hosts: all
tasks:
- name: install software-properties-common and update apt cache
apt:
name: software-properties-common
state: latest
update_cache: yes
cache_valid_time: 3600
become: yes
- name: add apt repository ppa ansible
apt_repository:
repo: ppa:ansible/ansible
become: yes
- name: install ansible
apt:
name: ansible
state: latest
become: yes
- name: deploy the vault_password file
copy:
src: ../files/.vault_password
dest: /root/.vault_password
owner: root
group: root
mode: "0600"
become: yes
- name: install git
apt:
name: git
state: latest
become: yes
- name: create the ansiblePull.service file
copy:
src: ../files/ansiblePull.service
dest: /etc/systemd/system/ansiblePull.service
become: yes
- name: create the ansiblePull.timer file
copy:
src: ../files/ansiblePull.timer
dest: /etc/systemd/system/ansiblePull.timer
become: yes
- name: make sure that the timer service is started
systemd:
name: ansiblePull.timer
state: started
enabled: yes
daemon_reload: yes
become: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment