Skip to content

Commit a1216ed

Browse files
author
Bryan Kendall
committed
adjust consul playbook to be repeatable
1 parent 4b66bac commit a1216ed

5 files changed

Lines changed: 15 additions & 6 deletions

File tree

ansible/beta-hosts/hosts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ api
2020
[api]
2121
beta-api
2222

23-
[consul-server]
23+
[consul]
2424
beta-services
2525
beta-api
2626
beta-web

ansible/consul.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
- hosts: consul
3+
serial: 1
34
vars_files:
45
- group_vars/alpha-consul.yml
56
roles:
67
- { role: notify, tags: notify }
78
- { role: database }
8-
- { role: container_start, tags: deploy }
9+
- { role: container_kill_start, tags: deploy }

ansible/group_vars/alpha-consul.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name: consul
33
# for database role
44
db_path: /etc/consul.d
55

6+
# for container_kill_start
7+
pause_length_minutes: 3
8+
69
container_image: progrium/consul
710
container_tag: latest
811

ansible/roles/base_ubuntu/tasks/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
hostname: name="{{inventory_hostname}}--{{ansible_default_ipv4.address|replace(".", "-")}}"
1313
tags: "hostname"
1414

15-
- lineinfile:
15+
- name: put hostname in /etc/hosts
16+
lineinfile:
1617
dest=/etc/hosts
1718
regexp="127.0.0.1 {{inventory_hostname}}--{{ansible_default_ipv4.address|replace(".", "-")}}"
1819
line="127.0.0.1 {{inventory_hostname}}--{{ansible_default_ipv4.address|replace(".", "-")}}"

ansible/roles/container_kill_start/tasks/main.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
with_items: stopped_containers.stdout_lines
1111

1212
# get current running container with this image
13-
- name: look for running containers running {{container_image}}
13+
- name: look for running containers running target image
1414
shell: "sudo docker ps | grep {{container_image}}: | awk '{print $1}'"
1515
register: old_containers_id
1616
changed_when: old_containers_id.stdout != ''
1717

1818
# get latest image
1919
# tag will default to latest
20-
- name: pull down docker image {{container_image}}:{{container_tag}}
20+
- name: pull down target docker image
2121
command: sudo docker pull {{container_image}}:{{container_tag}}
2222
when: not do_not_push
2323

2424
# get id of new image
25-
- name: get id of the docker image
25+
- name: get id of the target docker image
2626
shell: sudo docker images --no-trunc | grep {{container_image}}.*{{container_tag}} | awk '{print $3}'
2727
register: new_image_id
2828

@@ -38,6 +38,10 @@
3838
command: sudo docker rm {{item}}
3939
with_items: old_containers_id.stdout_lines
4040

41+
- name: pause to allow for any odd conditions in system caching tables
42+
when: pause_length_minutes is defined and old_containers_id.changed
43+
pause: minutes={{pause_length_minutes}}
44+
4145
# start our new container with options and args
4246
- name: start container
4347
command: sudo docker run --log-driver=none -v /var/log:/var/log:rw --restart=always {{container_run_opts}} {{container_image}}:{{container_tag}} {{container_run_args}}

0 commit comments

Comments
 (0)