title: Using ansible, what is the best way to add a line to an existing file that depends on the value of a variable passed by --extra-vars?
body: <p>I have a numerical config (e.g., number of milliseconds for some config) that needs to be set in a standard system file. I don't want to keep the whole config file in version control since it's part of a standard install. Is there a way to add a line to a file and have some variable replacement text in the line that can depend on a specified variable (e.g., passed via command line when the playbook is run using <code>--extra-vars</code>.</p>
  
  <p>For example, something like the following (my best effort so far):</p>
  
  <pre><code>- name: Set ring delay
    lineinfile:
      dest: /etc/cassandra/cassandra-env.sh
      state: present
      regexp: 'JVM_OPTS="$JVM_OPTS -Dcassandra.ring_delay_ms=.*"'
      line: 'JVM_OPTS="$JVM_OPTS -Dcassandra.ring_delay_ms=${ring_delay}"'
      backrefs: yes
    when: ring_delay is defined
  </code></pre>
  
  <p>where the playbook is executed with <code>ansible-playbook -e "ring_delay=10000"</code>
  The above example works fine if I don't have variable value for the config (e.g., I just hard code <code>line: 'JVM_OPTS="$JVM_OPTS -Dcassandra.ring_delay_ms=10000"'</code>, but I would like to be able to specify the value manually from the command line when I run the playbook. Is there a good way to do this? Ideally, rerunning the playbook would overwrite the ring_delay with the new value</p>
  
  <p>EDIT: From this <a href="https://groups.google.com/forum/#!topic/ansible-project/gOCEbYX5yTc" rel="nofollow">link</a>, It appears that the <code>${ring_delay}</code> notation I used above is not a feature of ansible, though there are a couple of examples on the web that suggest there is some related functionality for string replacement. The <a href="http://docs.ansible.com/lineinfile_module.html" rel="nofollow">docs</a> refer to "named backreferences", but I'm not sure what those are.</p>