2021-03-23 12:48:33 +00:00
|
|
|
#################################################
|
|
|
|
# DO Community Playbooks: Docker
|
|
|
|
#################################################
|
|
|
|
---
|
|
|
|
- hosts: all
|
|
|
|
become: true
|
|
|
|
vars_files:
|
|
|
|
- vars/frank.yml
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: Copy dockerfile
|
2021-06-23 04:11:56 +00:00
|
|
|
synchronize: src=app dest=/home/pi/dockerfile
|
2021-03-23 12:48:33 +00:00
|
|
|
|
|
|
|
- name: Build frank image
|
|
|
|
docker_image:
|
|
|
|
name: frank:latest
|
|
|
|
build:
|
2021-06-23 04:11:56 +00:00
|
|
|
path: /home/pi/dockerfile/app
|
|
|
|
dockerfile: /home/pi/dockerfile/app/frank.Dockerfile
|
2021-03-23 12:48:33 +00:00
|
|
|
pull: yes
|
|
|
|
state: present
|
|
|
|
source: build
|
|
|
|
|
2021-06-23 04:11:56 +00:00
|
|
|
- name: Check if frank .env file exists
|
|
|
|
stat: path="/home/pi/frank.env"
|
|
|
|
register: status
|
|
|
|
|
|
|
|
- name: No need to upload the frank .env file
|
|
|
|
debug: msg= {{ "No need to upload the frank .env file as it already exists." }}
|
|
|
|
|
|
|
|
- name: Upload the frank .env file
|
|
|
|
when: status.stat.exists == false
|
2021-03-23 12:48:33 +00:00
|
|
|
template:
|
2021-07-24 07:27:34 +00:00
|
|
|
src: files/frank.env
|
|
|
|
dest: /home/pi/frank.env
|
|
|
|
group: pi
|
|
|
|
owner: pi
|
|
|
|
mode: 0644
|
2021-03-23 12:48:33 +00:00
|
|
|
|
|
|
|
- name: Create frank worker container
|
|
|
|
docker_container:
|
|
|
|
name: "frank"
|
|
|
|
image: frank:latest
|
|
|
|
state: started
|
2021-06-23 04:11:56 +00:00
|
|
|
restart_policy: "no"
|
2021-03-23 12:48:33 +00:00
|
|
|
env_file: "/home/pi/frank.env"
|
|
|
|
network_mode: "host"
|
|
|
|
devices:
|
|
|
|
- "{{ printer_port }}:/printer"
|
2021-06-23 04:11:56 +00:00
|
|
|
|
|
|
|
- name: Copy docker build script
|
2021-07-24 07:27:34 +00:00
|
|
|
template:
|
|
|
|
src: files/build-frank.sh
|
|
|
|
dest: /home/pi/dockerfile/build-frank.sh
|
|
|
|
group: pi
|
|
|
|
owner: pi
|
|
|
|
mode: 0644
|
2021-06-23 04:11:56 +00:00
|
|
|
|
|
|
|
- name: Copy docker run script
|
2021-07-24 07:27:34 +00:00
|
|
|
template:
|
|
|
|
src: files/frank.sh
|
|
|
|
dest: /home/pi/dockerfile/frank.sh
|
|
|
|
group: pi
|
|
|
|
owner: pi
|
|
|
|
mode: 0644
|
2021-06-23 04:11:56 +00:00
|
|
|
|
|
|
|
- name: install frank systemd unit file
|
|
|
|
template:
|
|
|
|
src: "files/frank.service"
|
|
|
|
dest: "/etc/systemd/system/frank.service"
|
|
|
|
|
|
|
|
- name: enable service frank and ensure it is not masked
|
|
|
|
systemd:
|
|
|
|
name: frank
|
|
|
|
enabled: yes
|
|
|
|
masked: no
|
|
|
|
|
|
|
|
- name: Make sure frank service is running
|
|
|
|
systemd:
|
|
|
|
state: started
|
|
|
|
name: frank
|