<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">lineinfile</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.6.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/jsteel/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Jan  5 2018, 10:41:29) [GCC 7.2.1 20171224]"><pre class="notranslate"><code class="notranslate">ansible 2.6.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/jsteel/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Jan  5 2018, 10:41:29) [GCC 7.2.1 20171224]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Recent change <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="253305474" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/28721" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/28721/hovercard" href="https://github.com/ansible/ansible/issues/28721">#28721</a> breaks my config where I use both regexp AND insertafter; the regexp doesn't seem to match any more, so on every subsequent run it inserts duplicate lines.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- name: my.cnf options
  lineinfile:
    dest: &quot;{{ mariadb_config }}&quot;
    regexp: &quot;^{{ item.option }}=&quot;
    line: &quot;{{ item.option }}={{ item.value }}&quot;
    insertafter: '^\[{{ item.section }}\]'
  with_items:
     - { section: mysqld, option: innodb_log_file_size, value: &quot;{{ innodb_log_file_size }}&quot; }
     - { section: mysqld, option: default-storage-engine, value: innodb }
     - { section: mysqld, option: max_allowed_packet, value: 128M }"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">my.cnf options</span>
  <span class="pl-ent">lineinfile</span>:
    <span class="pl-ent">dest</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ mariadb_config }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">regexp</span>: <span class="pl-s"><span class="pl-pds">"</span>^{{ item.option }}=<span class="pl-pds">"</span></span>
    <span class="pl-ent">line</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item.option }}={{ item.value }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">insertafter</span>: <span class="pl-s"><span class="pl-pds">'</span>^\[{{ item.section }}\]<span class="pl-pds">'</span></span>
  <span class="pl-ent">with_items</span>:
     - <span class="pl-s">{ section: mysqld, option: innodb_log_file_size, value: "{{ innodb_log_file_size }}" }</span>
     - <span class="pl-s">{ section: mysqld, option: default-storage-engine, value: innodb }</span>
     - <span class="pl-s">{ section: mysqld, option: max_allowed_packet, value: 128M }</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">On subsequent runs, nothing should change.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">A duplicate line is inserted for each item, for eg:</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="--- before: /etc/my.cnf (content)
+++ after: /etc/my.cnf (content)
@@ -1,4 +1,5 @@
 [mysqld]
+default-storage-engine=innodb
 skip-name-resolve
 max_allowed_packet=128M
 default-storage-engine=innodb"><pre class="notranslate"><code class="notranslate">--- before: /etc/my.cnf (content)
+++ after: /etc/my.cnf (content)
@@ -1,4 +1,5 @@
 [mysqld]
+default-storage-engine=innodb
 skip-name-resolve
 max_allowed_packet=128M
 default-storage-engine=innodb
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/halberom/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/halberom">@halberom</a> on 2015-09-21T143421Z</p>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ec2_group module</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">_<br>
1.9.3<br>
devel<br>
_</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/halberom/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/halberom">@halberom</a> on 2015-09-21T14:34:21Z<br>
<em>Description</em></p>
<p dir="auto">Currently running ec2_group with a rule like</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="      - proto: tcp
        from_port: 9200
        to_port: 9200
        cidr_ip:
          - 10.220.130.0/27
          - 172.16.60.0/24"><pre class="notranslate"><code class="notranslate">      - proto: tcp
        from_port: 9200
        to_port: 9200
        cidr_ip:
          - 10.220.130.0/27
          - 172.16.60.0/24
</code></pre></div>
<p dir="auto">Works fine on the first run, but fails on the second with</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;Response&gt;&lt;Errors&gt;&lt;Error&gt;&lt;Code&gt;InvalidPermission.Duplicate&lt;/Code&gt;&lt;Message&gt;the specified rule &quot;peer: 10.220.130.0/27, TCP, from port: 9200, to port: 9200, ALLOW&quot; already exists&lt;/Message&gt;&lt;/Error&gt;&lt;/Errors&gt;&lt;RequestID&gt;1fdf97c8-e078-4d0d-89da-cf65e498b710&lt;/RequestID&gt;&lt;/Response&gt;"><pre class="notranslate"><code class="notranslate">&lt;Response&gt;&lt;Errors&gt;&lt;Error&gt;&lt;Code&gt;InvalidPermission.Duplicate&lt;/Code&gt;&lt;Message&gt;the specified rule "peer: 10.220.130.0/27, TCP, from port: 9200, to port: 9200, ALLOW" already exists&lt;/Message&gt;&lt;/Error&gt;&lt;/Errors&gt;&lt;RequestID&gt;1fdf97c8-e078-4d0d-89da-cf65e498b710&lt;/RequestID&gt;&lt;/Response&gt;
</code></pre></div>
<p dir="auto">It has been discussed <a href="https://groups.google.com/forum/#!msg/ansible-project/Int4x36MDmc/mZoXM9bOxIIJ" rel="nofollow">here</a>.</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">run an ec2_group task that creates the above rule, then re-run it</p>
<h5 dir="auto">Expected result</h5>
<p dir="auto">it creates the rules the first time, and then doens't make any changes or error the second time</p>
<h5 dir="auto">Actual result</h5>
<p dir="auto">it creates the rules the first time, and then errors</p>
<h5 dir="auto">Desired</h5>
<p dir="auto">Given that it works on the first run, and correctly creates the group and rules, it would be nice for it to work on subsequent runs.  Either that or write a fail statement and stop it working on the first run.</p>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="107526111" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/2120" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/2120/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/2120">ansible/ansible-modules-core#2120</a></p>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="107526111" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/2120" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/2120/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/2120">ansible/ansible-modules-core#2120</a></p>