yaml - How to escape a $ sign in an Ansible host_vars file -
i have ansible playbook (yaml) deploys web application and, part of deployment process, creates , initializes various databases , data in tables.
playbook task:
- name: insert meter managers mdm_connection shell : "psql -d {{ mdm_config_db }} -c \"insert mdm_connection (mdm_connection_type_id, name, db_type, host, port, catalog, username, password) values (3, '{{ item.name }}', '{{ item.db_type }}', '{{ item.host }}', {{ item.port }}, '{{ item.catalog }}', '{{ item.username }}', '{{ item.password }}');\"" with_items: "{{ meter_managers }}" when: item != "" sudo_user: postgres tags: - initdb
host_vars:
meter_managers: - name: sample db_type: "" host: "http://www.example.com/axis2/services/example/" port: -1 catalog: "" username: csa1 password: "example$example"
you can ignore of parameters above, part isn't working password field, contains $ sign.
it comes out example, truncated after $ sign.
i have tried escape double $$ instead, per link: how can escape $ dollar sign in docker compose file?
however, not result in right output. comes out as
example15887example
where number in between different each time run playbook. have no idea number coming from. seems kind of tick, or that, link seems suggest $$ way escape single $ , don't see why that's coming out that.
i have tried , without enclosing " marks , tried or without ' marks, no avail.
any idea how escape can value example$example ready insertion database table?
update:
the referenced question not have answered question without additional explanation, anthon has described simplification below in comments , assisted far better in question.
you feed string $
bash.
in bash $
variable prefix.
, $$
special variable current pid number, different every time run playbook.
in bash when use double quotes $
should appear \$
. see use double quotes in yaml well, should try escape slash well, try password: "example\\$example"
.
Comments
Post a Comment