summaryrefslogtreecommitdiff
path: root/roles
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@fretlink.com>2018-11-28 10:11:57 +0100
committerIsmaël Bouya <ismael.bouya@fretlink.com>2018-11-28 10:12:39 +0100
commitb7b8fe64fb3ed13ef535c7d4789da3a5001e355d (patch)
treea2f99cd0a18013f748d7817aa286f27effd23312 /roles
parent386f9271125f93651cb20420de696efab8798fa9 (diff)
downloadAnsible-b7b8fe64fb3ed13ef535c7d4789da3a5001e355d.tar.gz
Ansible-b7b8fe64fb3ed13ef535c7d4789da3a5001e355d.tar.zst
Ansible-b7b8fe64fb3ed13ef535c7d4789da3a5001e355d.zip
Move environment file to template
Diffstat (limited to 'roles')
-rw-r--r--roles/contexts/fretlink/tasks/main.yml11
-rw-r--r--roles/contexts/fretlink/templates/environment.j2202
-rw-r--r--roles/shell/bash/templates/bashrc.j29
3 files changed, 214 insertions, 8 deletions
diff --git a/roles/contexts/fretlink/tasks/main.yml b/roles/contexts/fretlink/tasks/main.yml
index 99d39b3..0908eca 100644
--- a/roles/contexts/fretlink/tasks/main.yml
+++ b/roles/contexts/fretlink/tasks/main.yml
@@ -72,15 +72,10 @@
72 - start 72 - start
73 - name: environment variables file 73 - name: environment variables file
74 block: 74 block:
75 - name: extract environment 75 - name: environment file
76 shell: "pass show Travail/Fretlink/Environment" 76 template:
77 register: fretlink_environment 77 src: environment.j2
78 changed_when: false
79 check_mode: no
80 - name: store environment
81 copy:
82 dest: $HOME/workdir/environment 78 dest: $HOME/workdir/environment
83 content: "{{ fretlink_environment.stdout }}"
84 rescue: 79 rescue:
85 - debug: 80 - debug:
86 msg: "Could not read password store, continuing" 81 msg: "Could not read password store, continuing"
diff --git a/roles/contexts/fretlink/templates/environment.j2 b/roles/contexts/fretlink/templates/environment.j2
new file mode 100644
index 0000000..bb9328a
--- /dev/null
+++ b/roles/contexts/fretlink/templates/environment.j2
@@ -0,0 +1,202 @@
1# vim: filetype=sh
2# Macaron
3# openssl rand -hex 32
4# URI: postgres:///db_name
5
6DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
7if ! $(echo "$PATH" | grep -q "$DIR/toolbox/scripts"); then
8 PATH="$DIR/toolbox/scripts:$PATH"
9fi
10
11build_macaroon() {
12 if [ "$1" = "--old" ]; then
13 shift
14 action="old-realms"
15 ttl=""
16 else
17 action="new"
18 ttl="--no-ttl"
19 fi
20
21 if [ -z "$1" -o -z "$2" -o -z "$3" -o -z "$4" ]; then
22 echo "build_macaroon [--old] secret src-key-id target realm" >&2
23 return
24 fi
25
26 secret="$1"
27 src="$2"
28 target="uri://fretlink/$3"
29 realm="$4"
30
31 cd "$HOME/workdir/haskell-commons"
32 MACAROON_PRIVATE_KEY="$secret" MACAROON_SECRET="$secret" stack exec macaroon-bakery -- $action --location "$target" --key-id "$src" $ttl "$realm"
33}
34
35APP=$(basename $(pwd))
36
37FL_APPS_HOST="localhost"
38FL_APPS_SCHEME="http"
39
40FL_ADMIN_ROOT_PORT=8079
41FL_ADMIN_ROOT_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/AdminRoot subkey=PrivateKey') }}"
42FL_ADMIN_ROOT_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_ADMIN_ROOT_PORT/api/"
43
44FL_APP_PORT=8080
45FL_APP_MONGO_URI="mongodb://localhost:27017/fretlink"
46FL_APP_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/App subkey=Secret') }}"
47FL_APP_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_APP_PORT"
48
49FL_CARRIER_DIRECTORY_PORT=8082
50FL_CARRIER_DIRECTORY_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/CarrierDirectory subkey=Secret') }}"
51FL_CARRIER_DIRECTORY_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/CarrierDirectory subkey=PrivateKey') }}"
52FL_CARRIER_DIRECTORY_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_CARRIER_DIRECTORY_PORT/api/"
53
54FL_NOTIFIER_PORT=8081
55FL_NOTIFIER_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Notifier subkey=Secret') }}"
56FL_NOTIFIER_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Notifier subkey=PrivateKey') }}"
57FL_NOTIFIER_URL="$FL_APPS_SCHEME://$FL_APPS_HOST:$FL_NOTIFIER_PORT/api"
58
59FL_PRICER_PORT=8083
60FL_PRICER_PRIVATE_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Pricer subkey=PrivateKey') }}"
61
62FL_FREIGHT_PORT=8084
63FL_FREIGHT_SECRET="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/Freight subkey=Secret') }}"
64
65FL_BOOKKEEPING_SECRET="dummy"
66
67FL_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=Host') }}"
68FL_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=Port') }}"
69FL_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local subkey=User') }}"
70FL_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Local') }}"
71
72FL_GEODATA_DEV_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=Host') }}"
73FL_GEODATA_DEV_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=Port') }}"
74FL_GEODATA_DEV_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=User') }}"
75FL_GEODATA_DEV_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata') }}"
76FL_GEODATA_DEV_PSQL_DB="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Geodata subkey=Database') }}"
77
78FL_NOTIFIER_DEV_PSQL_HOST="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=Host') }}"
79FL_NOTIFIER_DEV_PSQL_PORT="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=Port') }}"
80FL_NOTIFIER_DEV_PSQL_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=User') }}"
81FL_NOTIFIER_DEV_PSQL_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier') }}"
82FL_NOTIFIER_DEV_PSQL_DB="{{ lookup('passwordstore', 'Travail/Fretlink/Psql/Dev/Notifier subkey=Database') }}"
83
84FL_TOOLBOX_AGENT_MACAROON="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/ToolboxAgent') }}"
85
86if [ -f "local.env.example" ]; then
87 source local.env.example
88fi
89
90if [ "$APP" != "app" ]; then
91 name="${APP//-/_}"
92 port_var="FL_${name^^}_PORT"
93 secret_var="FL_${name^^}_SECRET"
94 private_key_var="FL_${name^^}_PRIVATE_KEY"
95
96 if [ -n "${!secret_var}" ]; then
97 export MACAROON_SECRET="${!secret_var}"
98 fi
99 if [ -n "${!private_key_var}" ]; then
100 export MACAROON_PRIVATE_KEY="${!private_key_var}"
101 fi
102 export PORT="${!port_var}"
103 export PG_URI="postgres:///$name"
104
105 if [ -z "$FL_ENV" ]; then
106 export POSTGRESQL_ADDON_HOST="$FL_PSQL_HOST"
107 export POSTGRESQL_ADDON_PORT="$FL_PSQL_PORT"
108 export POSTGRESQL_ADDON_USER="$FL_PSQL_USER"
109 export POSTGRESQL_ADDON_PASSWORD="$FL_PSQL_PASSWORD"
110 export POSTGRESQL_ADDON_DB="$name"
111 else
112 postgresql_host="FL_${name^^}_${FL_ENV^^}_PSQL_HOST"
113 postgresql_port="FL_${name^^}_${FL_ENV^^}_PSQL_PORT"
114 postgresql_user="FL_${name^^}_${FL_ENV^^}_PSQL_USER"
115 postgresql_password="FL_${name^^}_${FL_ENV^^}_PSQL_PASSWORD"
116 postgresql_db="FL_${name^^}_${FL_ENV^^}_PSQL_DB"
117 export FRETLINK_ENV="$FL_ENV"
118 export POSTGRESQL_ADDON_HOST="${!postgresql_host}"
119 export POSTGRESQL_ADDON_PORT="${!postgresql_port}"
120 export POSTGRESQL_ADDON_USER="${!postgresql_user}"
121 export POSTGRESQL_ADDON_PASSWORD="${!postgresql_password}"
122 export POSTGRESQL_ADDON_DB="${!postgresql_db}"
123 fi
124fi
125
126if [ "$APP" = "app" ]; then
127 export FRETLINK_MONGO_URI="$FL_APP_MONGO_URI"
128 export FRETLINK_PORT="$FL_APP_PORT"
129 export FRETLINK_BASE_URL="$FL_APP_URL"
130
131 # Dummies mandatory but not defined by default
132 export FRETLINK_SMTP_PASSWORD="password"
133 export FRETLINK_AMAZON_PUBLIC_KEY="password"
134 export FRETLINK_AMAZON_PRIVATE_KEY="password"
135 export FRETLINK_GMAPS_API_KEY="password"
136
137 # secret
138 export FRETLINK_MACAROON_SECRET=$FL_APP_SECRET
139
140 # carrier directory
141 export CARRIER_DIRECTORY_URI="$FL_CARRIER_DIRECTORY_URL"
142 export FRETLINK_CARDIR_URL="$FL_CARRIER_DIRECTORY_URL"
143 export FRETLINK_CARDIR_ENABLED="true"
144
145 # notifier
146 export FRETLINK_NOTIFIER_API=$FL_NOTIFIER_URL
147 export FRETLINK_NOTIFIER_ACCESS_KEY="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier messaging)"
148 export FRETLINK_NOTIFIER_TRANSPOREON_ACCESS_KEY="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier external)"
149 export FRETLINK_NOTIFIER_TRANSPOREON_ENABLED="true"
150
151 # admin-root
152 export FRETLINK_ADMINROOT_URL=$FL_ADMIN_ROOT_URL
153 export FRETLINK_ADMINROOT_ACCESS_KEY="$(build_macaroon $FL_ADMIN_ROOT_PRIVATE_KEY admin-root admin-root admin-root::token-delivery)"
154
155 # geodata
156 export FRETLINK_GEODATA_API="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/GeodataDev subkey=Url') }}"
157 export FRETLINK_GEODATA_ACCESS_KEY="{{ lookup('passwordstore', 'Travail/Fretlink/Macaroons/GeodataDev') }}"
158fi
159
160if [ "$APP" = "admin-root" ]; then
161 export BASE_URL=$FL_APPS_HOST
162 export API_ROOT="http://$BASE_URL:$PORT/api"
163 export UI_ROOT="http://$BASE_URL:$PORT/admin"
164 export TOK="$(build_macaroon $FL_ADMIN_ROOT_PRIVATE_KEY admin-root admin-root admin-root::provisioning)"
165
166 export CARDIR_MACAROON_SECRET=$FL_CARRIER_DIRECTORY_SECRET
167 export NOTIFIER_MACAROON_SECRET=$FL_NOTIFIER_SECRET
168 export BOOKKEEPING_MACAROON_SECRET=$FL_BOOKKEEPING_SECRET
169fi
170
171if [ "$APP" = "carrier-directory" ]; then
172 export ADMIN_BASE_URL=$FL_APP_URL
173fi
174
175if [ "$APP" = "notifier" ]; then
176 export MAILGUN_API_KEY="dummy"
177 export MAILGUN_DOMAIN="dummy"
178 export TEMPLATES_ASSETS_BASE_URL="http://dummy/"
179 export TRANSPOREON_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/ApiTest subkey=Login') }}"
180 export TRANSPOREON_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/ApiTest') }}"
181 export TRANSPOREON_CALLBACK_USER="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/NotifierCallbackTest subkey=Login') }}"
182 export TRANSPOREON_CALLBACK_PASSWORD="{{ lookup('passwordstore', 'Travail/Fretlink/Transporeon/NotifierCallbackTest') }}"
183
184 # Used by curl
185 # v2
186 #export MACAROON="$(build_macaroon $FL_NOTIFIER_SECRET notifier notifier external)"
187 # v1
188 export MACAROON="$(build_macaroon --old $FL_NOTIFIER_PRIVATE_KEY notifier notifier external)"
189
190 # To push transporeon cargos to app
191 APP_TRANSPOREON_PUSH_MACAROON="$(build_macaroon $FL_APP_SECRET notifier app app::transporeon-cargos-write)"
192fi
193
194if [ "$APP" = "pricer" ]; then
195 export GOOGLE_AUTH_CLIENT_ID="dummy"
196fi
197
198if [ "$APP" = "toolbox" ]; then
199 export AGENT_HOST=$FL_APP_URL
200 export AGENT_PATH="/"
201 export AGENT_MACAROON=$FL_TOOLBOX_AGENT_MACAROON
202fi
diff --git a/roles/shell/bash/templates/bashrc.j2 b/roles/shell/bash/templates/bashrc.j2
index 1357475..c7f8522 100644
--- a/roles/shell/bash/templates/bashrc.j2
+++ b/roles/shell/bash/templates/bashrc.j2
@@ -53,6 +53,15 @@ if [ -n "$TMUX" ]; then
53 TMUX_SESSION_NAME=$(tmux display-message -p "#S") 53 TMUX_SESSION_NAME=$(tmux display-message -p "#S")
54 export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history" 54 export HISTFILE="$XDG_STATE_HOME/bash/tmux_${TMUX_SESSION_NAME}_history"
55fi 55fi
56
57function load_dev_env() {
58 if [ -z "$1" ]; then
59 source ../environment
60 else
61 FL_ENV="$1" source ../environment
62 fi
63}
64
56##### /Fretlink 65##### /Fretlink
57{% endif %} 66{% endif %}
58 67