From dc984f4d05889a240e6a81b442b4cfd249bcf22f Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Mon, 4 Dec 2017 00:24:53 -0800 Subject: Use ansible-pull to propagate changes --- bootstrap.yml | 8 +++++++ hosts | 7 ++---- local.yml | 18 +++++++++++++++ roles/ansible-pull/tasks/main.yml | 27 ++++++++++++++++++++++ .../templates/etc_cron.d_metamorphosis.j2 | 2 ++ .../templates/etc_logrotate.d_metamorphosis.j2 | 7 ++++++ .../templates/usr_local_bin_metamorphose.j2 | 13 +++++++++++ site.yml | 8 ------- 8 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 bootstrap.yml create mode 100644 local.yml create mode 100644 roles/ansible-pull/tasks/main.yml create mode 100644 roles/ansible-pull/templates/etc_cron.d_metamorphosis.j2 create mode 100644 roles/ansible-pull/templates/etc_logrotate.d_metamorphosis.j2 create mode 100644 roles/ansible-pull/templates/usr_local_bin_metamorphose.j2 delete mode 100644 site.yml diff --git a/bootstrap.yml b/bootstrap.yml new file mode 100644 index 0000000..5bbe75a --- /dev/null +++ b/bootstrap.yml @@ -0,0 +1,8 @@ +# This playbook bootstraps hosts to run ansible-pull. +# +# Adapted from https://github.com/ansible/ansible-examples/blob/master/language_features/ansible_pull.yml +--- +- hosts: pull_mode_hosts + remote_user: root + roles: + - ansible-pull diff --git a/hosts b/hosts index 66bd4ef..07ace09 100644 --- a/hosts +++ b/hosts @@ -1,6 +1,3 @@ [all] -vps - -## virtual private servers -[vps] -peter.crashbox.io \ No newline at end of file +peter.crashbox.io +7c2b258159ab \ No newline at end of file diff --git a/local.yml b/local.yml new file mode 100644 index 0000000..72ab863 --- /dev/null +++ b/local.yml @@ -0,0 +1,18 @@ +--- +- name: peter + hosts: peter.crashbox.io + tasks: + - name: test + shell: echo "run by peter" + +- name: test + hosts: 7c2b258159ab + tasks: + - name: test + shell: echo "run by container" + +- name: test2 + hosts: all + tasks: + - name: test + shell: echo "run by all" diff --git a/roles/ansible-pull/tasks/main.yml b/roles/ansible-pull/tasks/main.yml new file mode 100644 index 0000000..1f36000 --- /dev/null +++ b/roles/ansible-pull/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: install ansible + apt: name=ansible state=latest + +- name: install gnupg + apt: name=gpg state=latest + +- name: install git + apt: name=git state=latest + +- name: create ansible pull script + template: + src=templates/usr_local_bin_metamorphose.j2 + dest=/usr/local/bin/metamorphose + owner=root group=root mode=0755 + +- name: create crontab entry to clone/pull git repository + template: + src=templates/etc_cron.d_metamorphosis.j2 + dest=/etc/cron.d/metamorphosis + owner=root group=root mode=0644 + +- name: create logrotate entry for metamorphose.log + template: + src=templates/etc_logrotate.d_metamorphosis.j2 + dest=/etc/logrotate.d/metamorphosis + owner=root group=root mode=0644 diff --git a/roles/ansible-pull/templates/etc_cron.d_metamorphosis.j2 b/roles/ansible-pull/templates/etc_cron.d_metamorphosis.j2 new file mode 100644 index 0000000..a4c9541 --- /dev/null +++ b/roles/ansible-pull/templates/etc_cron.d_metamorphosis.j2 @@ -0,0 +1,2 @@ +# Cron job to git clone/pull a repo and then run locally +*/15 * * * * root /usr/local/bin/pull >>/var/log/pull.log 2>&1 \ No newline at end of file diff --git a/roles/ansible-pull/templates/etc_logrotate.d_metamorphosis.j2 b/roles/ansible-pull/templates/etc_logrotate.d_metamorphosis.j2 new file mode 100644 index 0000000..b81abbf --- /dev/null +++ b/roles/ansible-pull/templates/etc_logrotate.d_metamorphosis.j2 @@ -0,0 +1,7 @@ +/var/log/pull.log { + rotate 7 + daily + compress + missingok + notifempty +} \ No newline at end of file diff --git a/roles/ansible-pull/templates/usr_local_bin_metamorphose.j2 b/roles/ansible-pull/templates/usr_local_bin_metamorphose.j2 new file mode 100644 index 0000000..d416526 --- /dev/null +++ b/roles/ansible-pull/templates/usr_local_bin_metamorphose.j2 @@ -0,0 +1,13 @@ +#!/bin/sh +# Pull ansible configuration and upgrade system +set -e + +workdir=/var/lib/ansible/local + +mkdir --parents "$workdir" +/usr/bin/ansible-pull \ + --verify-commit \ + --checkout master \ + --sleep 10 \ + --directory "$workdir" \ + --url "https://github.com/jodersky/metamorphic.git" diff --git a/site.yml b/site.yml deleted file mode 100644 index 19a8add..0000000 --- a/site.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: crashbox - become: true - hosts: peter.crashbox.io - remote_user: root - roles: - - common - - webserver -- cgit v1.2.3