@@ -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" ,
0 commit comments