Deploy via Ansible, including cronjob
This commit is contained in:
parent
17d4e1e5f2
commit
27c660f9e3
5 changed files with 58 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
env
|
||||
inventory
|
||||
|
|
|
@ -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
|
||||
```
|
5
ansible.cfg
Normal file
5
ansible.cfg
Normal file
|
@ -0,0 +1,5 @@
|
|||
[defaults]
|
||||
inventory=inventory
|
||||
|
||||
[ssh_connection]
|
||||
pipelining = True
|
37
ansible.yml
Normal file
37
ansible.yml
Normal file
|
@ -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"
|
8
inventory.example
Normal file
8
inventory.example
Normal file
|
@ -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
|
Loading…
Reference in a new issue