I need to pass ssl_ca
to mysql_db
module only if mysql_use_ssl
is defined. Is this possible using one task, like:
mysql_db: name=mydb state=import target=/tmp/mysql.sql login_host="mydbhost" login_user="root" login_password="password" {% if mysql_use_ssl %}ssl_ca=/path/to/cert.pem{% endif %}
?
This actual snippet does not work, result:
{"failed": true, "msg": "template error while templating string: Encountered unknown tag 'endif'.. String: /path/to/cert.pem{% endif %}"}
When moving the conditional as:
mysql_db: name=mydb state=import target=/tmp/mysql.sql login_host="mydbhost" login_user="root" login_password="password" ssl_ca="{% if mysql_use_ssl %}/path/to/cert.pem{% else %}none{% endif %}"
Then it "works" but none
is not a supported parameter for turning off mysql ssl connection, so it does not turn off ssl.
There is omit keyword/variable for this:
mysql_db:
name: mydb
state: import
target: /tmp/mysql.sql
login_host: mydbhost
login_user: root
login_password: password
ssl_ca: "{{ '/path/to/cert.pem' if mysql_use_ssl | default(false) else omit }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With