title: Replacing a string with regex using replace module in Ansible
body: <p>I need to replace a string with <code>app_name: &lt;anything&gt;</code> to <code>app_name: {{ node }}</code>.</p>
  
  <p>There is some syntax error while tried to execute using the replace module below:</p>
  
  <blockquote>
    <p>replace: dest=/ABC/hybris/newrelic/newrelic.yml regexp='app_name:\s[A-Za-z0-9 ]*' replace='app_name: "{{ node }}"'</p>
  </blockquote>
  
  <p>Error Message:</p>
  
  <pre><code>[ansible@dev-ci ansible]$ ansible-playbook -i hosts_acc ACC.yml --tags=newrelic
  ERROR! Syntax Error while loading YAML.
  
  
  The error appears to have been in '/ABC/Ansible/roles/NewRelic_Base/tasks/main.yml': line 12, column 101, but may
  be elsewhere in the file depending on the exact syntax problem.
  
  The offending line appears to be:
  
  - name: NewRelic - Replace app_name variable
    replace: dest=/ABC/hybris/newrelic/newrelic.yml regexp='app_name:\s[A-Za-z0-9 ]*' replace="app_name: {{ node }}"
                                                                                                      ^ here
  We could be wrong, but this one looks like it might be an issue with
  missing quotes.  Always quote template expression brackets when they
  start a value. For instance:
  
      with_items:
        - {{ foo }}
  
  Should be written as:
  
      with_items:
        - "{{ foo }}"
  </code></pre>