<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/slash3g/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/slash3g">@slash3g</a> on 2016-04-10T16:37:22Z</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.0.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.0.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<p dir="auto">(bug still present in devel branch)</p>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">Default Ansible configuration.</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">lxc_container handles container configuration via the container_configuration parameter. Unfortunately, the logic behind the configuration update is broken, as it duplicates the key and never replaces old values. Morever, when the configuration file contains duplicated keys, the script can fail to make any changes.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">Exec the following playbook</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- hosts: myhost
  tasks:
      - name: fist config update
        lxc_container:
            name: mycontainer
            container_config:
                - &quot;lxc.start.auto = 0&quot;
      - name: second config update
        lxc_container:
            name: mycontainer
            container_config:
                - &quot;lxc.start.auto = 1&quot;"><pre class="notranslate"><code class="notranslate">
---
- hosts: myhost
  tasks:
      - name: fist config update
        lxc_container:
            name: mycontainer
            container_config:
                - "lxc.start.auto = 0"
      - name: second config update
        lxc_container:
            name: mycontainer
            container_config:
                - "lxc.start.auto = 1"
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ grep start mycontainer/config
lxc.start.auto  =  1"><pre class="notranslate"><code class="notranslate">$ grep start mycontainer/config
lxc.start.auto  =  1
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ grep start mycontainer/config
lxc.start.auto  =  0
lxc.start.auto  =  1"><pre class="notranslate"><code class="notranslate">$ grep start mycontainer/config
lxc.start.auto  =  0
lxc.start.auto  =  1
</code></pre></div>
<p dir="auto">Copied from original issue: <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>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">Conditionals</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.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]"><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.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

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

<p dir="auto">Have discovered this with Ubuntu 17.04 managing Centos 7.3.<br>
Reproduced for this report with Ubuntu 17.04 targeting itself.</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">is defined works as expected when the variable it is used against is not defined.<br>
However, when the variable exists, but depends on an undefined variable, it fails, instead of returning false.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">Will upload a minimal test case role.</p>
<p dir="auto">Run:<br>
ansible-playbook -i inventory playbook.yml</p>


<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">The role def has 2 conditional steps. Since the variables are (directly or indirectly) not defined, they should both be skipped.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">The 2nd task makes the playbook fail.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK [def : Problematic step.] **********************************************************************************************************************************************************************
fatal: [thismachine]: FAILED! =&gt; {&quot;failed&quot;: true, &quot;msg&quot;: &quot;The conditional check 'dependent is defined' failed. The error was: error while evaluating conditional (dependent is defined): I use {{ variable }}.: 'variable' is undefined\n\nThe error appears to have been in '/home/xalkina/tmp/defined/roles/def/tasks/main.yml': line 9, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Problematic step.\n  ^ here\n&quot;}
        to retry, use: --limit @/home/xalkina/tmp/defined/playbook.retry"><pre class="notranslate"><code class="notranslate">TASK [def : Problematic step.] **********************************************************************************************************************************************************************
fatal: [thismachine]: FAILED! =&gt; {"failed": true, "msg": "The conditional check 'dependent is defined' failed. The error was: error while evaluating conditional (dependent is defined): I use {{ variable }}.: 'variable' is undefined\n\nThe error appears to have been in '/home/xalkina/tmp/defined/roles/def/tasks/main.yml': line 9, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Problematic step.\n  ^ here\n"}
        to retry, use: --limit @/home/xalkina/tmp/defined/playbook.retry
</code></pre></div>