82 lines
2.0 KiB
YAML
Executable File
82 lines
2.0 KiB
YAML
Executable File
#################################################
|
|
# DO Community Playbooks: Docker
|
|
#################################################
|
|
---
|
|
- hosts: all
|
|
become: true
|
|
vars_files:
|
|
- vars/frank.yml
|
|
|
|
tasks:
|
|
- name: Copy dockerfile
|
|
synchronize: src=app dest=/home/pi/dockerfile
|
|
|
|
- name: Build frank image
|
|
docker_image:
|
|
name: frank:latest
|
|
build:
|
|
path: /home/pi/dockerfile/app
|
|
dockerfile: /home/pi/dockerfile/app/frank.Dockerfile
|
|
pull: yes
|
|
state: present
|
|
source: build
|
|
|
|
- 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
|
|
template:
|
|
src: files/frank.env
|
|
dest: /home/pi/frank.env
|
|
group: pi
|
|
owner: pi
|
|
mode: 0644
|
|
|
|
- name: Create frank worker container
|
|
docker_container:
|
|
name: "frank"
|
|
image: frank:latest
|
|
state: started
|
|
restart_policy: "no"
|
|
env_file: "/home/pi/frank.env"
|
|
network_mode: "host"
|
|
devices:
|
|
- "{{ printer_port }}:/printer"
|
|
|
|
- name: Copy docker build script
|
|
template:
|
|
src: files/build-frank.sh
|
|
dest: /home/pi/dockerfile/build-frank.sh
|
|
group: pi
|
|
owner: pi
|
|
mode: 0644
|
|
|
|
- name: Copy docker run script
|
|
template:
|
|
src: files/frank.sh
|
|
dest: /home/pi/dockerfile/frank.sh
|
|
group: pi
|
|
owner: pi
|
|
mode: 0644
|
|
|
|
- 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
|