Skip to content

Commit d4c8e67

Browse files
authored
Merge pull request #631 from CodeNow/conditionally-add-vault-tokens
Vault tokens will only be added to the user-data script and then to t…
2 parents 9125054 + 7777c22 commit d4c8e67

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

ansible/roles/builder/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
tags: [ deploy ]
5656
become: true
5757
copy:
58-
src=../../../secrets/docker-client/{{ file_name_item }}
58+
src=./secrets/docker-client/{{ file_name_item }}
5959
dest={{ build_dir }}/{{ name }}
6060
owner=ubuntu
6161
group=ubuntu

ansible/roles/dock_launch_config/tasks/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- app_name: "krain"
1212
- enviroment_vars: enviroment_vars
1313

14+
# this requires the use of gnu/coreutils base64 (`brew install coreutils`)
15+
# Allows us to use same base64 locally and in host
1416
- name: encode krain config to base64
1517
shell: cat ~/{{ app_name }}.conf | base64 -w 0
1618
register: krain_base64
@@ -29,7 +31,9 @@
2931
- app_name: "charon"
3032
- enviroment_vars: enviroment_vars
3133

32-
- name: encode krain config to base64
34+
# this requires the use of gnu/coreutils base64 (`brew install coreutils`)
35+
# Allows us to use same base64 locally and in host
36+
- name: encode charon config to base64
3337
shell: cat ~/{{ app_name }}.conf | base64 -w 0
3438
register: charon_base64
3539
vars:

ansible/roles/dock_launch_config/templates/init.tmpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ export CONSUL_PORT={{ consul_api_port }}
55
export CONSUL_HOSTNAME={{ consul_host_address }}
66
export VAULT_PORT={{ vault_port }}
77

8+
{% set has_token = ( s3_access_key is defined and
9+
s3_secret_key is defined and
10+
aws_access_key is defined and
11+
aws_secret_key is defined ) %}
12+
13+
{% if not has_token %}
814
# Create directory for env
915
mkdir -p /opt/runnable/dock-init/consul-resources/vault/{{ node_env }}
1016
chown ubuntu:ubuntu /opt/runnable/dock-init/consul-resources/vault/{{ node_env }}
@@ -14,6 +20,7 @@ chmod 0711 /opt/runnable/dock-init/consul-resources/vault/{{ node_env }}
1420
{% for item in tokens %}
1521
echo {{ item.value }} > /opt/runnable/dock-init/consul-resources/vault/{{ node_env }}/{{ item.file_name }}
1622
{% endfor %}
23+
{% endif %}
1724

1825
# Add upstart files for charon and krain
1926
mkdir -p /docker/app-logs/
@@ -34,5 +41,9 @@ start amazon-ssm-agent
3441
service krain start
3542
service charon start
3643
{% if not is_dock_pool %}
44+
{% if has_token %}
45+
CONSUL_HOSTNAME={{ consul_host_address }} CONSUL_PORT={{ consul_api_port }} VAULT_PORT={{ vault_port }} S3_ACCESS_KEY={{ s3_access_key }} S3_SECRET_KEY={{ s3_secret_key }} AWS_ACCESS_KEY={{ aws_access_key }} AWS_SECRET_KEY={{ aws_secret_key }} bash /opt/runnable/dock-init/init.sh | tee /var/log/user-script-dock-init.log
46+
{% else %}
3747
CONSUL_HOSTNAME={{ consul_host_address }} CONSUL_PORT={{ consul_api_port }} VAULT_PORT={{ vault_port }} bash /opt/runnable/dock-init/init.sh | tee /var/log/user-script-dock-init.log
3848
{% endif %}
49+
{% endif %}

0 commit comments

Comments
 (0)