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
|
2023-08-28 05:33:00 +00:00
|
|
|
synchronize: src=app dest="/home/{{ user }}/dockerfile"
|
2021-03-23 12:48:33 +00:00
|
|
|
|
|
|
|
- name: Build frank image
|
|
|
|
docker_image:
|
|
|
|
name: frank:latest
|
|
|
|
build:
|
2023-08-28 05:33:00 +00:00
|
|
|
path: "/home/{{ user }}/dockerfile/app"
|
|
|
|
dockerfile: "/home/{{ user }}/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
|
2023-08-28 05:33:00 +00:00
|
|
|
stat: path="/home/{{ user }}/frank.env"
|
2021-06-23 04:11:56 +00:00
|
|
|
register: status
|
|
|
|
|
|
|
|
- name: No need to upload the frank .env file
|
2024-12-16 12:23:21 +00:00
|
|
|
debug:
|
|
|
|
msg: "No need to upload the frank .env file as it already exists."
|
2021-06-23 04:11:56 +00:00
|
|
|
|
|
|
|
- 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
|
2023-08-28 05:33:00 +00:00
|
|
|
dest: "/home/{{ user }}/frank.env"
|
|
|
|
group: "{{ user }}"
|
|
|
|
owner: "{{ user }}"
|
2021-07-24 07:27:34 +00:00
|
|
|
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"
|
2023-08-28 05:33:00 +00:00
|
|
|
env_file: "/home/{{ user }}/frank.env"
|
2021-03-23 12:48:33 +00:00
|
|
|
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
|
2023-08-28 05:33:00 +00:00
|
|
|
dest: "/home/{{ user }}/dockerfile/build-frank.sh"
|
|
|
|
group: "{{ user }}"
|
|
|
|
owner: "{{ user }}"
|
2021-07-24 07:27:34 +00:00
|
|
|
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
|
2023-08-28 05:33:00 +00:00
|
|
|
dest: "/home/{{ user }}/dockerfile/frank.sh"
|
|
|
|
group: "{{ user }}"
|
|
|
|
owner: "{{ user }}"
|
2021-07-24 07:27:34 +00:00
|
|
|
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
|