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