From 27c660f9e3f12213c78d681045e6ff6014fb7dca Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 10 Sep 2019 16:16:31 +0200 Subject: [PATCH] Deploy via Ansible, including cronjob --- .gitignore | 1 + README.md | 7 +++++++ ansible.cfg | 5 +++++ ansible.yml | 37 +++++++++++++++++++++++++++++++++++++ inventory.example | 8 ++++++++ 5 files changed, 58 insertions(+) create mode 100644 ansible.cfg create mode 100644 ansible.yml create mode 100644 inventory.example diff --git a/.gitignore b/.gitignore index 0a764a4..1f02023 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ env +inventory diff --git a/README.md b/README.md index f70b8a9..e5d8f3a 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,10 @@ cd communistquotes sudo docker run -it --rm --name communistquotes --env-file env communistquotes sudo docker run -it --rm --name communistquotes --env-file ../env communistquotes ``` + +## Deploy + +Copy `inventory.example` to `inventory`, and enter your server's ssh address. Then run the following command: +``` +ansible-playbook ansible.yml --become +``` \ No newline at end of file diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..960a7c4 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,5 @@ +[defaults] +inventory=inventory + +[ssh_connection] +pipelining = True diff --git a/ansible.yml b/ansible.yml new file mode 100644 index 0000000..2741c6e --- /dev/null +++ b/ansible.yml @@ -0,0 +1,37 @@ +--- +- hosts: all + + # Install python if required + # https://www.josharcher.uk/code/ansible-python-connection-failure-ubuntu-server-1604/ + gather_facts: False + pre_tasks: + - name: install python for Ansible + raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-setuptools) + args: + executable: /bin/bash + register: output + changed_when: output.stdout != "" + - setup: # gather facts + + tasks: + - name: clone/update git repo + git: + repo: 'https://0xacab.org/radical_coder/pinko.red.git' + dest: /pinkored + + - name: Build image using cache source + docker_image: + name: communistquotes:latest + build: + path: /pinkored/communistquotes/ + pull: yes + source: build + + - name: add all template files + template: src=env dest=/pinkored/env + + - name: create crontab + cron: + name: "communist-quotes" + hour: "*/3" + job: "docker run -it --rm --name communistquotes --env-file /pinkored/env communistquotes >> /var/log/communistquotes.log 2>&1" diff --git a/inventory.example b/inventory.example new file mode 100644 index 0000000..18dcaa3 --- /dev/null +++ b/inventory.example @@ -0,0 +1,8 @@ +[pinko.red] +# define the username and hostname that you use for ssh connection, and specify the domain +myuser@example.com +# you can also use a host that is defined in your ssh config +myserver + +[all:vars] +ansible_connection=ssh