From 7265a116f493262b51884ff9776d85a2e871bbc7 Mon Sep 17 00:00:00 2001 From: Ubergeek Date: Mon, 18 Mar 2019 12:53:49 +0000 Subject: [PATCH] updating the perms on cron tasks, adding systemd units, and adding the hook logics --- roles/common/files/ansible-run | 7 +++++ roles/common/files/ansible-run.path | 6 ++++ roles/common/files/ansible-run.service | 4 +++ roles/common/tasks/ansible-pull.yml | 38 ++++++++++++++++++++++++-- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 roles/common/files/ansible-run create mode 100644 roles/common/files/ansible-run.path create mode 100644 roles/common/files/ansible-run.service diff --git a/roles/common/files/ansible-run b/roles/common/files/ansible-run new file mode 100644 index 0000000..b84c6d1 --- /dev/null +++ b/roles/common/files/ansible-run @@ -0,0 +1,7 @@ +#!/bin/bash + +cd /var/thunix/ansible +/usr/bin/git pull +/usr/local/bin/ansible-playbook -i /var/thunix/ansible/hosts /var/thunix/ansible/site.yml -u root +rm /dev/shm/run-ansible +touch /dev/shm/ansible-hook-last-run diff --git a/roles/common/files/ansible-run.path b/roles/common/files/ansible-run.path new file mode 100644 index 0000000..cb34d91 --- /dev/null +++ b/roles/common/files/ansible-run.path @@ -0,0 +1,6 @@ +[Unit] +Description=ansible-run path +[Path] +PathModified=/dev/shm/run-ansible +[Install] +WantedBy=multi-user.target diff --git a/roles/common/files/ansible-run.service b/roles/common/files/ansible-run.service new file mode 100644 index 0000000..9f6679b --- /dev/null +++ b/roles/common/files/ansible-run.service @@ -0,0 +1,4 @@ +[Unit] +Description=ansible-run +[Service] +ExecStart=/usr/local/bin/ansible-run diff --git a/roles/common/tasks/ansible-pull.yml b/roles/common/tasks/ansible-pull.yml index 73903a1..8104afa 100644 --- a/roles/common/tasks/ansible-pull.yml +++ b/roles/common/tasks/ansible-pull.yml @@ -3,14 +3,46 @@ src: ../files/ansible-pull dest: /etc/cron.hourly/ansible-pull owner: root - mode: 775 - + mode: 0755 + +- name: Add githook local script + copy: + src: ../files/ansible-run + dest: /usr/local/bin/ansible-run + owner: root + mode: 0755 + +- name: Add githook systemd path unit + copy: + src: ../files/ansible-run.path + dest: /etc/systemd/system/ansible-run.path + owner: root + group: root + mode: 0644 + +- name: Add githook system service unit + copy: + src: ../files/ansible-run.service + dest: /etc/systemd/system/ansible-run.service + owner: root + group: root + mode: 0644 + +- name: Enabling ansible-pull units + systemd: + name: "{{ item }}" + enabled: yes + state: started + with_items: + - 'ansible-pull.path' + - 'ansible-pull.service' + - name: Add mirror rsync cron job copy: src: ../files/mirror-rsync dest: /etc/cron.daily/mirror-rsync owner: root - mode: 775 + mode: 0775 - name: Adding ansible git repo locally git: