Skip to content

Commit 3fb256f

Browse files
fix: logic error during decryption
1 parent e5ad0b3 commit 3fb256f

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

solutions/standard-openshift/ansible/main.tf

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ resource "terraform_data" "execute_playbooks" {
122122
# Decrypt ocp config if it already exists
123123
provisioner "remote-exec" {
124124
inline = [
125-
"if [ -f \"/root/.powervs/config.json\" ]; then",
126-
" if ! ( head -n 1 /root/.powervs/config.json | grep -q '^$ANSIBLE_VAULT' ); then",
125+
"if [ -f /root/.powervs/config.json ]; then",
126+
" if head -n 1 /root/.powervs/config.json | grep -q '^$ANSIBLE_VAULT'; then",
127127
" echo ${var.ansible_vault_password} > password_file",
128128
" ansible-vault decrypt /root/.powervs/config.json --vault-password-file password_file",
129129
" fi",
@@ -132,10 +132,13 @@ resource "terraform_data" "execute_playbooks" {
132132
}
133133

134134
# Execute bash shell script to run ansible playbooks
135+
# create password file so the script can encrypt the ocp config
135136
provisioner "remote-exec" {
136137
inline = [
138+
"echo ${var.ansible_vault_password} > password_file",
137139
"chmod +x ${local.dst_script_file_path}",
138140
"export IBMCLOUD_API_KEY=${local.ibmcloud_api_key} && ${local.dst_script_file_path}",
141+
"rm -f password_file"
139142
]
140143
}
141144

@@ -149,7 +152,7 @@ resource "terraform_data" "execute_playbooks" {
149152
# Encrypt ocp config if it already exists
150153
provisioner "remote-exec" {
151154
inline = [
152-
"if [ -f \"/root/.powervs/config.json\" ]; then",
155+
"if [ -f /root/.powervs/config.json ]; then",
153156
" if ! ( head -n 1 /root/.powervs/config.json | grep -q '^$ANSIBLE_VAULT' ); then",
154157
" echo ${var.ansible_vault_password} > password_file",
155158
" ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file",
@@ -234,8 +237,8 @@ resource "terraform_data" "execute_playbooks_with_vault" {
234237
# Decrypt ocp config if it already exists
235238
provisioner "remote-exec" {
236239
inline = [
237-
"if [ -f \"/root/.powervs/config.json\" ]; then",
238-
" if ! ( head -n 1 /root/.powervs/config.json | grep -q '^$ANSIBLE_VAULT' ); then",
240+
"if [ -f /root/.powervs/config.json ]; then",
241+
" if head -n 1 /root/.powervs/config.json | grep -q '^$ANSIBLE_VAULT'; then",
239242
" ansible-vault decrypt /root/.powervs/config.json --vault-password-file password_file",
240243
" fi",
241244
"fi"
@@ -253,7 +256,7 @@ resource "terraform_data" "execute_playbooks_with_vault" {
253256
# Encrypt ocp config if it already exists
254257
provisioner "remote-exec" {
255258
inline = [
256-
"if [ -f \"/root/.powervs/config.json\" ]; then",
259+
"if [ -f /root/.powervs/config.json ]; then",
257260
" if ! ( head -n 1 /root/.powervs/config.json | grep -q '^$ANSIBLE_VAULT' ); then",
258261
" echo ${var.ansible_vault_password} > password_file",
259262
" ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +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 "/root/.powervs/config.json" ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
27+
if [ -f /root/.powervs/config.json ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
2828
rm -f password_file
2929
rm -rf $${ansible_private_key_file}
3030
exit 1
3131
fi
3232
echo \"Playbook command successful\"
3333
rm -rf $${ansible_private_key_file}
34-
if [ -f "/root/.powervs/config.json" ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
34+
if [ -f /root/.powervs/config.json ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
3535
rm -f password_file

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +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 "/root/.powervs/config.json" ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
27+
if [ -f /root/.powervs/config.json ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
2828
rm -f password_file
2929
rm -rf $${ansible_private_key_file}
3030
exit 1
3131
fi
3232
echo \"Playbook command successful\"
3333
rm -rf $${ansible_private_key_file}
34-
if [ -f "/root/.powervs/config.json" ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
34+
if [ -f /root/.powervs/config.json ]; then ansible-vault encrypt /root/.powervs/config.json --vault-password-file password_file; fi
3535
rm -f password_file

0 commit comments

Comments
 (0)