‘Database Name [default: postcodesiodb]’: ‘postcodesiodb’
‘Postgresql Port [default: 5432]’: ‘5432’
tags:
setup
install
test
Below is the only error logging I have but it’s failed at the first input I am attempting to populate here the postgres Super user. Any ideas how I need to pass in these answers and or variables if I don’t want to hard code? Currently it just looks like it is picking up "] characters.
The wording / syntax of the questions when the script is called is exactly like this:
Postgresql Superuser (for database creation) [default: postgres]:
I have tried various combinations to frame my inputs e.g.
But they all seem to produce the same error message. The pexpect module documentation is very limited esp in terms of examples. I am not needing to use pexpect if there are other know working solutions to automate this with ansible.
name: Setup postcodesiodb
expect:
echo: yes
chdir: “/apps/was/postcodes.io”
command: npm run setup
timeout: “10”
responses:
‘Postgresql Superuser (for database creation) [default: postgres]’: ‘postgres’
‘New Database Username (for readonly access) [default: postcodesio]’: ‘postcodesio’
‘Password for new user [default: secret]’: ‘secret’
‘Postgresql Host [default: localhost]’: ‘localhost’
‘Database Name [default: postcodesiodb]’: ‘postcodesiodb’
‘Postgresql Port [default: 5432]’: 5432
tags:
setup
install
test
The task is no longer producing that error and I can see the values being populated with the exception the the final Port value which still does not look to be parsing “5432” correctly. I have tried removing the single quotes around it, to make it clear it is an integer as opposed to a string but that has made no difference. I also can’t see any discrepancies with the escape characters used for regex compared to the previous responses which are now working. Any ideas what I need to do to close this off?
FAILED! => {“changed”: true, “cmd”: “npm run setup”,
…
Apply read-only privileges for the new user to the new database", “”, “Postgresql Superuser (for database creation) [default: postgres]:postgres”, “New Database Username (for readonly access) [default: postcodesio]:postcodesio”, “Password for new user [default: secret]:secret”, “Postgresql Host [default: localhost]:localhost”, “Database Name [default: postcodesiodb]:postcodesiodb”, “Postgresql Port: [default: 5432]:”]}
I see what I was doing the wrong. The last question of the interactive script was framed slightly differently and included an extra colon immediately after the word Port which I had omitted:
Postgresql Port: [default: 5432]:
Now I have added this colon to my final response, the pexpect module is working a treat.