<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Feature Idea</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">lib/ansible/modules/clustering/consul_kv.py</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">ansible 2.3.0.0<br>
ansible 2.4.0.0</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Currently the <code class="notranslate">consul_kv</code> module does not provide any extra diff output (when running ansible with the so useful <code class="notranslate">--diff</code> option).<br>
Diff output (we could make it optional, by an extra optional parameter like 'diffView') should be easy to add using the  <code class="notranslate">module.exit_json</code> <code class="notranslate">diff</code> return attribute containing both the old and new value for the updated key, in following fashion:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    index, existing = consul_api.kv.get(key)
    ...
    # to support diff-mode, just need following block:
    if existing and existing['Value']:
        ansible_diff = {'before': existing['Value'],  'after': value}
    else:
        ansible_diff = None

    module.exit_json(changed=changed,
                     index=index,
                     key=key,
                     data=stored,
                     diff= ansible_diff
)"><pre class="notranslate"><code class="notranslate">    index, existing = consul_api.kv.get(key)
    ...
    # to support diff-mode, just need following block:
    if existing and existing['Value']:
        ansible_diff = {'before': existing['Value'],  'after': value}
    else:
        ansible_diff = None

    module.exit_json(changed=changed,
                     index=index,
                     key=key,
                     data=stored,
                     diff= ansible_diff
)
</code></pre></div>
<p dir="auto">Note: <del>Untested code</del><br>
Update: I've already tested the new <code class="notranslate">--diff</code> successfully in a duplicated consul_kv.py file. TODO make a PR etc</p>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">lxc_container</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]"><pre class="notranslate"><code class="notranslate">ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">This issue is a follow-up (but it's not a duplicate: that issue was about something different but still contains relevant messages) for the <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="147239210" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-extras/issues/1998" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-extras/issues/1998/hovercard" href="https://github.com/ansible/ansible-modules-extras/issues/1998">ansible/ansible-modules-extras#1998</a>.</p>
<p dir="auto">In short, if you change the <code class="notranslate">container_config</code> it's easy to reach the state when the config contains duplicates.</p>
<p dir="auto">I understand <code class="notranslate">lxc</code> allows some configuration directives to present multiple times in the config, but at least the module could de-duplicate the entries that are guaranteed to be unique.</p>
<p dir="auto">Eg: <code class="notranslate">lxc.start.auto</code>. Having duplicates for it really can cause issues when you expect (or do not) the container to start on the host restart, but due to multiple duplicate lines arbitrarily ordered - the outcome is basically random.</p>
<p dir="auto">What I suggest: what if the module kept the list of directives that are guaranteed to be unique and for those only kept the currently set values, and removed everything else.</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: Create a container
  lxc_container:
    name: container-to-demonstrate-duplicate-issues
    template: ubuntu
    state: started
    template_options: &quot;--release xenial&quot;
    container_config:
        - &quot;lxc.start.auto = 1&quot;"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">Create a container</span>
  <span class="pl-ent">lxc_container</span>:
    <span class="pl-ent">name</span>: <span class="pl-s">container-to-demonstrate-duplicate-issues</span>
    <span class="pl-ent">template</span>: <span class="pl-s">ubuntu</span>
    <span class="pl-ent">state</span>: <span class="pl-s">started</span>
    <span class="pl-ent">template_options</span>: <span class="pl-s"><span class="pl-pds">"</span>--release xenial<span class="pl-pds">"</span></span>
    <span class="pl-ent">container_config</span>:
        - <span class="pl-s"><span class="pl-pds">"</span>lxc.start.auto = 1<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">then change to <code class="notranslate">lxc.start.auto = 0</code></p>

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

<p dir="auto">There should be just one <code class="notranslate">lxc.start.auto</code> in the container's <code class="notranslate">config</code> file.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">There are 2 entries</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate">
</code></pre></div>