aboutsummaryrefslogtreecommitdiff
path: root/roles/ansible-pull
diff options
context:
space:
mode:
authorDevan Carpenter <git@dvn.me>2020-05-13 16:11:54 +0100
committerDevan Carpenter <git@dvn.me>2020-05-13 16:11:54 +0100
commitefaaee0ebe8c2f7fe715894c2941282cd29913e7 (patch)
treeffc070e43b85e5a2852875967fa2fd4523dc194c /roles/ansible-pull
downloadansible-basic-efaaee0ebe8c2f7fe715894c2941282cd29913e7.tar.gz
ansible-basic-efaaee0ebe8c2f7fe715894c2941282cd29913e7.zip
add roles to get startedHEADmaster
Diffstat (limited to 'roles/ansible-pull')
-rw-r--r--roles/ansible-pull/tasks/main.yml33
-rw-r--r--roles/ansible-pull/templates/ansible-pull.sh31
-rw-r--r--roles/ansible-pull/templates/pull.fact13
-rw-r--r--roles/ansible-pull/vars/main.yaml2
4 files changed, 79 insertions, 0 deletions
diff --git a/roles/ansible-pull/tasks/main.yml b/roles/ansible-pull/tasks/main.yml
new file mode 100644
index 0000000..7414bd9
--- /dev/null
+++ b/roles/ansible-pull/tasks/main.yml
@@ -0,0 +1,33 @@
1- name: Update apt cache
2 apt: update_cache=yes
3
4- name: Install depends
5 apt:
6 name: [python3-pip, ansible]
7 state: present
8
9- name: Ensure /etc/ansible/facts.d exists
10 file:
11 path: /etc/ansible/facts.d
12 state: directory
13 recurse: yes
14
15- name: Make /etc/ansible/facts.d/pull.fact
16 template:
17 src: pull.fact
18 dest: /etc/ansible/facts.d/pull.fact
19
20- name: recollect facts
21 setup:
22
23- name: Install the ansible-pull script
24 template: src=ansible-pull.sh dest=/usr/sbin/run-ansible-pull mode=0755 owner=root group=root
25
26- name: Install cronjob
27 cron: name="Ansible Pull" minute="{{ ansible_local.pull.minute | default(59 | random) }}" job="/usr/sbin/run-ansible-pull"
28
29- name: ensure ansible-pull is run on reboot
30 cron:
31 name: run ansible on reboot
32 job: /usr/sbin/run-ansible-pull
33 special_time: reboot
diff --git a/roles/ansible-pull/templates/ansible-pull.sh b/roles/ansible-pull/templates/ansible-pull.sh
new file mode 100644
index 0000000..56dcb9a
--- /dev/null
+++ b/roles/ansible-pull/templates/ansible-pull.sh
@@ -0,0 +1,31 @@
1#!/bin/bash
2
3if [ "$1" == "nodisown" ]; then
4 # Sometimes the $PATH gets messed up in cron, so lets start by setting the record straight
5 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
6 if [[ -d /usr/ansible ]]; then rm -rf /usr/ansible; fi
7 ansible-pull -U {{ ansible_local.pull.repo }} -C {{ ansible_local.pull.branch }} -d /var/run/ansible/basic &> /var/log/ansible.log
8 code=$?
9
10 if [[ "$code" -ne "0" ]]; then
11 # ansible localhost -m irc -a "server=irc.oftc.net use_ssl=yes port=6697 channel=# msg='[$(hostname -f)] Ansible Pull failed.' nick=ansible-$RANDOM color=red timeout=60"
12 exit 1
13 fi
14
15{% if ansible_fqdn in additional_playbooks %}
16{% for playbook in additional_playbooks[ansible_fqdn] %}
17 ansible-pull -U {{ playbooks[playbook.name] }} {% if 'branch' in playbook %}-C {{ playbook.branch}} {% endif %} -d /var/run/ansible/{{playbook.name}}&> /var/log/ansible-{{ playbook.name }}.log
18 code=$?
19
20 if [[ "$code" -ne "0" ]]; then
21 # ansible localhost -m irc -a "server=irc.oftc.net use_ssl=yes port=6697 channel=# msg='[$(hostname -f)] ansible-pull failed with additional playbook {{ playbook.name }}' nick=ansible-$RANDOM color=red"
22 exit 1
23 fi
24
25{% endfor %}
26{% endif %}
27 # ansible localhost -m irc -a "server=irc.oftc.net use_ssl=yes port=6697 channel=# msg='[$(hostname -f)] Ansible Pull successfully ran' nick=ansible-$RANDOM color=green"
28
29else
30 $0 nodisown & disown
31fi
diff --git a/roles/ansible-pull/templates/pull.fact b/roles/ansible-pull/templates/pull.fact
new file mode 100644
index 0000000..ac87804
--- /dev/null
+++ b/roles/ansible-pull/templates/pull.fact
@@ -0,0 +1,13 @@
1{
2{% if ansible_local is defined and ansible_local.pull is defined and ansible_local.pull is mapping %}
3 "repo": "{% if ansible_local.pull.repo %}{{ ansible_local.pull.repo }}{% else %}https://git.gnunet.org/ansible-basic.git{% endif %}",
4 "branch": "{% if ansible_local.pull.branch %}{{ ansible_local.pull.branch }}{% else %}master{% endif %}",
5 "minute": {% if ansible_local.pull.minute %}{{ ansible_local.pull.minute }}{% else %}{{ 59 | random }}{% endif %}
6
7{% else %}
8 "repo": "https://git.gnunet.org/ansible-basic.git",
9 "branch": "master",
10 "minute": "{{ 59 | random }}"
11
12{% endif %}
13}
diff --git a/roles/ansible-pull/vars/main.yaml b/roles/ansible-pull/vars/main.yaml
new file mode 100644
index 0000000..8b856a6
--- /dev/null
+++ b/roles/ansible-pull/vars/main.yaml
@@ -0,0 +1,2 @@
1playbooks:
2 gitlab-runner: https://git.gnunet.org/ansible-gitlab-runner.git