Skip to content

Commit 3579c23

Browse files
fix: check if file is encrypted before decrypting
1 parent f879c5a commit 3579c23

File tree

1 file changed

+11
-3
lines changed
  • solutions/standard-openshift/ansible

1 file changed

+11
-3
lines changed

solutions/standard-openshift/ansible/main.tf

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ 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 echo ${var.ansible_vault_password} > password_file; fi",
126-
"if [ -f \"/root/.powervs/config.json\" ]; then ansible-vault decrypt /root/.powervs/config.json --vault-password-file password_file; fi"
125+
"if [ -f \"/root/.powervs/config.json\" ]; then",
126+
" if ! ( head -n 1 | grep -q '^\\$ANSIBLE_VAULT' ); then",
127+
" echo ${var.ansible_vault_password} > password_file",
128+
" ansible-vault decrypt /root/.powervs/config.json --vault-password-file password_file",
129+
" fi",
130+
"fi"
127131
]
128132
}
129133

@@ -230,7 +234,11 @@ resource "terraform_data" "execute_playbooks_with_vault" {
230234
# Decrypt ocp config if it already exists
231235
provisioner "remote-exec" {
232236
inline = [
233-
"if [ -f \"/root/.powervs/config.json\" ]; then ansible-vault decrypt /root/.powervs/config.json --vault-password-file password_file; fi"
237+
"if [ -f \"/root/.powervs/config.json\" ]; then",
238+
" if ! ( head -n 1 | grep -q '^\\$ANSIBLE_VAULT' ); then",
239+
" ansible-vault decrypt /root/.powervs/config.json --vault-password-file password_file",
240+
" fi",
241+
"fi"
234242
]
235243
}
236244

0 commit comments

Comments
 (0)