Skip to content

Commit 14ba28a

Browse files
fix: add encrypting to ansible exec scripts
1 parent a55d556 commit 14ba28a

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

solutions/standard-openshift/ansible/main.tf

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ resource "terraform_data" "execute_playbooks" {
123123
provisioner "remote-exec" {
124124
inline = [
125125
"if [ -f \"~/.powervs/config.json\" ]; then echo ${var.ansible_vault_password} > password_file",
126-
"if [ -f \"~/.powervs/config.json\" ]; then ansible-vault decrypt ~/.powervs/config.json --vault-password-file password_file",
127-
"rm -f password_file"
126+
"if [ -f \"~/.powervs/config.json\" ]; then ansible-vault decrypt ~/.powervs/config.json --vault-password-file password_file"
128127
]
129128
}
130129

@@ -227,9 +226,7 @@ resource "terraform_data" "execute_playbooks_with_vault" {
227226
# Decrypt ocp config if it already exists
228227
provisioner "remote-exec" {
229228
inline = [
230-
"if [ -f \"~/.powervs/config.json\" ]; then echo ${var.ansible_vault_password} > password_file",
231-
"if [ -f \"~/.powervs/config.json\" ]; then ansible-vault decrypt ~/.powervs/config.json --vault-password-file password_file",
232-
"rm -f password_file"
229+
"if [ -f \"~/.powervs/config.json\" ]; then ansible-vault decrypt ~/.powervs/config.json --vault-password-file password_file"
233230
]
234231
}
235232

@@ -241,23 +238,24 @@ resource "terraform_data" "execute_playbooks_with_vault" {
241238
]
242239
}
243240

244-
# Again delete Ansible Vault password used to encrypt the var
245-
# files with sensitive information and private ssh key
241+
# Encrypt ocp config if it already exists
246242
provisioner "remote-exec" {
247243
inline = [
248-
"rm -rf password_file",
249-
"rm -rf ${local.private_key_file}"
244+
"if [ -f \"~/.powervs/config.json\" ]; then echo ${var.ansible_vault_password} > password_file",
245+
"if [ -f \"~/.powervs/config.json\" ]; then ansible-vault encrypt ~/.powervs/config.json --vault-password-file password_file",
246+
"rm -f password_file"
250247
]
251248
}
252249

253-
# Encrypt ocp config if it already exists
250+
# Again delete Ansible Vault password used to encrypt the var
251+
# files with sensitive information and private ssh key
254252
provisioner "remote-exec" {
255253
inline = [
256-
"if [ -f \"~/.powervs/config.json\" ]; then echo ${var.ansible_vault_password} > password_file",
257-
"if [ -f \"~/.powervs/config.json\" ]; then ansible-vault encrypt ~/.powervs/config.json --vault-password-file password_file",
258-
"rm -f password_file"
254+
"rm -rf password_file",
255+
"rm -rf ${local.private_key_file}"
259256
]
260257
}
258+
261259
}
262260

263261

solutions/standard-openshift/ansible/templates-ansible/deploy-openshift-cluster/ansible_exec.sh.tftpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ export IBMCLOUD_API_KEY=$${IBMCLOUD_API_KEY}
2424
unbuffer ansible-playbook -i $${ansible_inventory} $${ansible_playbook} --extra-vars "IBMCLOUD_API_KEY=$IBMCLOUD_API_KEY"
2525
## On failure:
2626
if [ $? -ne 0 ]; then
27+
if [ -f "~/.powervs/config.json" ]; then ansible-vault encrypt ~/.powervs/config.json --vault-password-file password_file
28+
rm -f password_file
2729
rm -rf $${ansible_private_key_file}
2830
exit 1
2931
fi
3032
echo \"Playbook command successful\"
3133
rm -rf $${ansible_private_key_file}
34+
if [ -f "~/.powervs/config.json" ]; then ansible-vault encrypt ~/.powervs/config.json --vault-password-file password_file
35+
rm -f password_file

solutions/standard-openshift/ansible/templates-ansible/deploy-openshift-cluster/ansible_exec_vault.sh.tftpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ export IBMCLOUD_API_KEY=$${IBMCLOUD_API_KEY}
2424
unbuffer ansible-playbook -i $${ansible_inventory} $${ansible_playbook} --extra-vars "IBMCLOUD_API_KEY=$IBMCLOUD_API_KEY" --vault-password-file password_file
2525
## On failure:
2626
if [ $? -ne 0 ]; then
27+
if [ -f "~/.powervs/config.json" ]; then ansible-vault encrypt ~/.powervs/config.json --vault-password-file password_file
28+
rm -f password_file
2729
rm -rf $${ansible_private_key_file}
2830
exit 1
2931
fi
3032
echo \"Playbook command successful\"
3133
rm -rf $${ansible_private_key_file}
34+
if [ -f "~/.powervs/config.json" ]; then ansible-vault encrypt ~/.powervs/config.json --vault-password-file password_file
35+
rm -f password_file

0 commit comments

Comments
 (0)