communistquotes/ansible.yml

56 lines
1.7 KiB
YAML

---
- hosts: all
become: yes
# 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: create folder for build files
file: path=/tmp/communistquotes state=directory
- name: copy all build files recursively
copy: src={{ item.from }} dest={{ item.to }}
with_items:
- { from: 'src/', to: '/tmp/communistquotes/src/' }
- { from: 'quotes/', to: '/tmp/communistquotes/quotes' }
- name: Build image using cache source
docker_image:
name: communistquotes:latest
build:
path: /tmp/communistquotes/
dockerfile: src/Dockerfile
pull: yes
source: build
force_source: yes
force_tag: yes
- name: delete build files
file: path=/tmp/communistquotes state=absent
- name: create config folder
file: path={{ item.path }} state=directory mode=700
with_items:
- { path: '/etc/communistquotes/' }
- { path: '/etc/communistquotes/secrets/' }
- name: add env file
copy: src=env dest=/etc/communistquotes/env mode=600
- name: create crontab
cron:
name: "communist-quotes"
hour: "*/3"
minute: "0"
job: "perl -le 'sleep rand 10800' && docker run --rm --name communistquotes -v /etc/communistquotes/secrets/:/etc/communistquotes/secrets/ --env-file /etc/communistquotes/env communistquotes >> /var/log/communistquotes.log 2>&1"