forked from geerlingguy/ansible-for-devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
55 lines (47 loc) · 1.38 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
- hosts: localhost
connection: local
gather_facts: false
vars:
base_image: node:8
container_name: hubot_slack
image_namespace: a4d
image_name: hubot-slack
pre_tasks:
- name: Make the latest version of the base image available locally.
docker_image:
name: '{{ base_image }}'
source: pull
force_source: true
- name: Create the Docker container.
docker_container:
image: '{{ base_image }}'
name: '{{ container_name }}'
command: sleep infinity
- name: Add the newly created container to the inventory.
add_host:
hostname: '{{ container_name }}'
ansible_connection: docker
roles:
- name: hubot-slack
delegate_to: '{{ container_name }}'
post_tasks:
- name: Clean up the container.
shell: >
apt-get remove --purge -y python &&
rm -rf /var/lib/apt/lists/*
delegate_to: '{{ container_name }}'
args:
warn: false
- name: Commit the container.
command: >
docker commit
-c 'USER hubot'
-c 'WORKDIR "/home/hubot"'
-c 'CMD ["bin/hubot", "--adapter", "slack"]'
-c 'VOLUME ["/home/hubot/scripts"]'
{{ container_name }} {{ image_namespace }}/{{ image_name }}:latest
- name: Remove the container.
docker_container:
name: '{{ container_name }}'
state: absent