title: How to escape a $ sign in an Ansible host_vars file
body: <p>I have a Ansible playbook (YAML) that deploys an web application and, as part of the deployment process, it creates and initializes various databases and some data in certain tables.</p>
  
  <p><strong>Playbook Task:</strong></p>
  
  <pre><code>  - name: insert Meter Managers to mdm_connection
      shell : "psql -d {{ mdm_config_db }} -c \"insert into 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
  </code></pre>
  
  <p><strong>host_vars:</strong></p>
  
  <pre><code>meter_managers:
    - name: SAMPLE
      db_type: ""
      host: "http://www.example.com/axis2/services/Example/"
      port: -1
      catalog: ""
      username: csa1
      password: "Example$Example"
  </code></pre>
  
  <p>You can ignore most of the parameters above, but the part that isn't working is the password field, as it contains a $ sign.</p>
  
  <p>It comes out as Example, truncated after the $ sign.</p>
  
  <p>I have tried to escape it as a double $$ instead, as per this link: <a href="https://stackoverflow.com/questions/40619582/how-can-i-escape-a-dollar-sign-in-a-yaml-string">How can I escape a $ dollar sign in a docker compose file?</a></p>
  
  <p>However, that does not result in the right output. It comes out as</p>
  
  <pre><code>Example15887Example
  </code></pre>
  
  <p>Where the number in between is different each time I run my playbook. I have no idea where that number is coming from. It seems to be some kind of tick, or something like that, but the link seems to suggest that $$ is the way to escape a single $ and so I don't see why that's coming out like that.</p>
  
  <p>I have also tried with and without enclosing <strong>"</strong> marks and also tried with or without <strong>'</strong> marks, but to no avail.</p>
  
  <p>Any idea as to how to properly escape this so that I can get the value Example$Example ready for insertion into my database table?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>The referenced question would not have answered my question without additional explanation, however Anthon has described the simplification below in comments and assisted far better in THIS question.</p>