Skip to content

Commit 2a0773c

Browse files
Merge pull request #418 from CodeNow/ansible-2
Ansible 2
2 parents 5bf0d3f + 7a38b02 commit 2a0773c

14 files changed

Lines changed: 96 additions & 62 deletions

File tree

ansible/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
_cache
12
*.pyc

ansible/ansible.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[defaults]
22
# Required so `sudo: yes` does not lose the environment variables, which hold the ssh-agent socket
3-
sudo_flags=-HE
3+
sudo_flags = -HE

ansible/group_vars/alpha-api-base.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repo: git@github.com:CodeNow/api.git
99
sendgrid_key: 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
1010

1111
# shared ENV's between api services
12-
api_base_container_envs: >
12+
api_base_container_envs: >-
1313
-e AWS_ACCESS_KEY_ID={{ api_aws_access_key_id }}
1414
-e AWS_SECRET_ACCESS_KEY={{ api_aws_secret_access_key }}
1515
-e COOKIE_DOMAIN={{ domain }}

ansible/group_vars/alpha-optimus.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
name: "optimus"
1+
name: optimus
22

3-
container_image: "registry.runnable.com/runnable/{{ name }}"
3+
container_image: registry.runnable.com/runnable/{{ name }}
44
container_tag: "{{ git_branch }}"
5-
repo: "git@github.com:CodeNow/{{ name }}.git"
5+
repo: git@github.com:CodeNow/{{ name }}.git
66
hosted_ports: ["{{ optimus_port }}"]
77
node_version: "4.3.2"
88
npm_version: "2.8.3"
99

1010
# for redis
11-
redis_key: "frontend:{{ optimus_hostname }}"
12-
is_redis_update_required: 'yes'
11+
redis_key: frontend:{{ optimus_hostname }}
12+
is_redis_update_required: yes
1313

1414
container_envs: >
1515
-e NODE_ENV={{ node_env }}
@@ -26,4 +26,4 @@ container_run_opts: >
2626
-h {{ name }}
2727
-d
2828
-P
29-
{{container_envs}}
29+
{{ container_envs }}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
- name: install build essentials
3-
sudo: true
3+
become: yes
44
action: apt
5-
pkg="build-essential"
6-
state=present
7-
update_cache=yes
8-
cache_valid_time=604800
5+
pkg: build-essential
6+
state: present
7+
update_cache: yes
8+
cache_valid_time: 604800
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
---
2-
build_dir: /opts/builds/docker_build/
2+
build_dir: /opts/builds/docker_build
33
npm_start_command: start

ansible/roles/builder/tasks/main.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,33 @@
33
- name: create build folder
44
become: true
55
file:
6-
path="{{ build_dir }}/{{ name }}"
7-
state=directory
6+
path: "{{ build_dir }}/{{ name }}"
7+
state: directory
88

99
- name: pull the git repository
1010
tags: deploy
1111
become: true
1212
git:
13-
repo="{{ repo }}"
14-
dest="{{ build_dir }}/{{ name }}/repo"
15-
version="{{ git_branch }}"
16-
update=yes
17-
accept_hostkey=True
18-
force=yes
13+
repo: "{{ repo }}"
14+
dest: "{{ build_dir }}/{{ name }}/repo"
15+
version: "{{ git_branch }}"
16+
update: yes
17+
accept_hostkey: yes
18+
force: yes
1919

2020
- name: copy dockerfile to build folder
2121
tags: deploy
2222
become: true
2323
template:
24-
src={{ dockerfile }}
25-
dest="{{ build_dir }}/{{ name }}"
24+
src: "{{ dockerfile }}"
25+
dest: "{{ build_dir }}/{{ name }}"
2626

2727
- name: build docker image and tag
2828
tags: deploy
29-
command: sudo docker build {{ build_args | default("") }} --tag="{{ container_image }}:{{ container_tag }}" "{{ build_dir }}/{{ name }}"
29+
become: yes
30+
command: docker build {{ build_args | default("") }} --tag="{{ container_image }}:{{ container_tag }}" "{{ build_dir }}/{{ name }}"
3031

3132
- name: push docker image
33+
become: yes
3234
when: not do_not_push
33-
command: sudo docker push {{ container_image }}:{{ container_tag }}
35+
command: docker push {{ container_image }}:{{ container_tag }}

ansible/roles/container_kill_start/handlers/main.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
- name: get new container ports
33
tags: deploy
44
when: hosted_ports is defined
5-
shell: sudo docker port {{new_container_id.stdout}} {{ hosted_ports[0] }} | awk --field-separator ':' '{print $2}'
5+
become: yes
6+
shell: docker port {{new_container_id.stdout}} {{ hosted_ports[0] }} | awk --field-separator ':' '{print $2}'
67
register: container_ports
78

89
# this assumes only one container is running, ever
910
- name: update redis key
1011
tags: deploy
11-
when: container_ports is defined
12-
command: sudo docker run --rm redis redis-cli -h {{redis_host_address}} lset {{redis_key}} 1 {{hosted_protocol | default('http') }}://{{ansible_default_ipv4.address}}:{{container_ports.stdout}}
13-
when: is_redis_update_required is defined
12+
when: container_ports is defined and is_redis_update_required is defined
13+
become: yes
14+
command: docker run --rm redis redis-cli -h {{redis_host_address}} lset {{redis_key}} 1 {{hosted_protocol | default('http') }}://{{ansible_default_ipv4.address}}:{{container_ports.stdout}}

ansible/roles/container_kill_start/tasks/main.yml

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
- name: "look for stopped {{ container_image }} containers"
1+
- name: look for stopped {{ container_image }} containers
22
tags: deploy
3+
become: yes
34
shell: >
4-
sudo docker ps -a |
5+
docker ps -a |
56
grep Exited |
67
grep {{ container_image }} |
78
awk '{print $1}'
89
register: stopped_containers
910
changed_when: stopped_containers.stdout != ''
1011

11-
- name: "removed stopped {{ container_image }} containers"
12+
- name: removed stopped {{ container_image }} containers
1213
tags: deploy
14+
become: yes
1315
when: stopped_containers.changed
14-
shell: sudo docker rm {{ item }}
15-
with_items: stopped_containers.stdout_lines
16+
shell: docker rm {{ item }}
17+
with_items: "{{ stopped_containers.stdout_lines }}"
1618

1719
# get current running container with this image
18-
- name: "look for running containers running {{ container_image }}"
20+
- name: look for running containers running {{ container_image }}
1921
tags: deploy
2022
become: true
2123
script: findTagRunning.sh {{ container_image }}
@@ -24,16 +26,18 @@
2426

2527
# get latest image
2628
# tag will default to latest
27-
- name: "pull down docker image {{ container_image }}:{{ container_tag }}"
29+
- name: pull down docker image {{ container_image }}:{{ container_tag }}
2830
tags: deploy
29-
command: sudo docker pull {{ container_image }}:{{ container_tag }}
31+
become: yes
32+
command: docker pull {{ container_image }}:{{ container_tag }}
3033
when: not do_not_push
3134

3235
# get id of new image
3336
- name: get id of the docker image
3437
tags: deploy
38+
become: yes
3539
shell: >
36-
sudo docker images
40+
docker images
3741
--no-trunc |
3842
grep {{ container_image }}.*{{ container_tag }} |
3943
awk '{print $3}'
@@ -43,32 +47,35 @@
4347
- name: stop old containers
4448
tags: deploy
4549
when: old_containers_id.changed
46-
command: sudo docker stop -t {{ stop_time }} {{ item }}
47-
with_items: old_containers_id.stdout_lines
50+
become: yes
51+
command: docker stop -t {{ stop_time }} {{ item }}
52+
with_items: "{{ old_containers_id.stdout_lines }}"
4853

4954
# remove the old containers that were running previously
5055
- name: remove old containers
5156
tags: deploy
5257
when: old_containers_id.changed
53-
command: sudo docker rm {{ item }}
54-
with_items: old_containers_id.stdout_lines
58+
become: yes
59+
command: docker rm {{ item }}
60+
with_items: "{{ old_containers_id.stdout_lines }}"
5561

5662
- name: pause to allow for any odd conditions in system caching tables
5763
tags: deploy
5864
when: pause_length_minutes is defined and old_containers_id.changed
59-
pause: minutes={{pause_length_minutes}}
65+
pause: minutes={{ pause_length_minutes }}
6066

6167
# start our new container with options and args
6268
- name: start container
6369
tags: deploy
70+
become: yes
6471
command: >
65-
sudo docker run
72+
docker run
6673
--log-driver={{ log_driver }}
6774
--log-opt syslog-facility={{ log_facility }}
6875
--log-opt tag="{{ log_tag | default ( name ) }}"
6976
-v {{ app_log_dir }}:{{ app_log_dir }}:rw
7077
--restart={{ restart_policy | default('always') }}
71-
{{ container_run_opts}}
78+
{{ container_run_opts }}
7279
{{ container_image }}:{{ container_tag }}
7380
{{ container_run_args }}
7481
register: new_container_id

ansible/roles/container_restart/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
when: force_stop is defined or (stopped_container.skipped and not running_containers.changed)
3535
tags: [ deploy ]
3636
become: yes
37-
shell: docker run {{ docker_container_run_opts }} {{ docker_image }}:{{ docker_image_version }}
37+
shell: docker run {{ docker_container_run_opts | trim }} {{ docker_image }}:{{ docker_image_version }}

0 commit comments

Comments
 (0)