49 lines
1.5 KiB
YAML
49 lines
1.5 KiB
YAML
---
|
|
- 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: create folder for build files
|
|
file: path=/tmp/communistquotes state=directory
|
|
|
|
# NOTE: It doesnt really make sense to call the folder "templates", when we actually dont use a
|
|
# template task...
|
|
- name: copy all build files recursively
|
|
copy: src=templates/ dest=/tmp/communistquotes
|
|
|
|
- name: Build image using cache source
|
|
docker_image:
|
|
name: communistquotes:latest
|
|
build:
|
|
path: /tmp/communistquotes
|
|
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=/etc/communistquotes state=directory mode=700
|
|
|
|
- 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 --env-file /etc/communistquotes/env communistquotes >> /var/log/communistquotes.log 2>&1"
|