summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2017-12-04 00:24:53 -0800
committerJakob Odersky <jakob@odersky.com>2017-12-04 01:09:28 -0800
commitdc984f4d05889a240e6a81b442b4cfd249bcf22f (patch)
tree4a020a98192f13b2a2ceab85aaf6b93e6a7b70da
parentc780b908f539b8042881a87007859797e0d6bdc4 (diff)
downloadmetamorphic-pull-based.tar.gz
metamorphic-pull-based.tar.bz2
metamorphic-pull-based.zip
Use ansible-pull to propagate changespull-based
-rw-r--r--bootstrap.yml8
-rw-r--r--hosts7
-rw-r--r--local.yml18
-rw-r--r--roles/ansible-pull/tasks/main.yml27
-rw-r--r--roles/ansible-pull/templates/etc_cron.d_metamorphosis.j22
-rw-r--r--roles/ansible-pull/templates/etc_logrotate.d_metamorphosis.j27
-rw-r--r--roles/ansible-pull/templates/usr_local_bin_metamorphose.j213
-rw-r--r--site.yml8
8 files changed, 77 insertions, 13 deletions
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