title: Adding a line to the middle of a file with Ansible
body: <p>I am trying to create an ansible playbook entry which looks for a php array</p>
  
  <pre><code>$array = {
    'some\value',
  };
  </code></pre>
  
  <p>And adds a line to that array</p>
  
  <pre><code>$array = {
    'some\value',
    'another\value,
  };
  </code></pre>
  
  <p>This is what I tried, and while it adds the line I'm after, it also keeps adding it every pass</p>
  
  <pre><code>- name: Add another\value dummy.php
    lineinfile:
      dest=/path/to/dummy.php
      insertafter='some\value'
      line="  'another\value',"
  </code></pre>
  
  <p>If I keep running the playbook, I'll get</p>
  
  <pre><code>$array = {
    'some\value',
    'another\value,
    'another\value,
    'another\value,
    'another\value,
    'another\value,
    'another\value,
  };
  </code></pre>
  
  <p>I realise I'm probably doing something really stupid here, but I can't see how to say <code>"unless_it_exists='another\value'"</code></p>
  
  <p>I also tried this, which doesn't work</p>
  
  <pre><code>- name: Add another\value dummy.php
    lineinfile:
      dest=/path/to/dummy.php
      regexp="'some\\value',\n}"
      backrefs=yes
      line="'some\\value'\n  'another\\value',\n}"
  </code></pre>
  
  <p><strong>Edited 2014-07-28</strong></p>
  
  <p>Just to clarify - the file I'm editing is <a href="https://github.com/laravel/laravel/blob/7e4107d453222bea687b8932a3b61d9b4bb410dd/app/config/app.php" rel="nofollow"><strong>this one</strong> https://github.com/...</a> and I'm trying to add an array member at line 124, like this:</p>
  
  <pre><code>        'Way\Generators\GeneratorsServiceProvider',
  </code></pre>