<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">yum</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.2.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">No changes to ansible.cfg, and no ANSIBLE_* environment variables are set</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Control machine: Arch Linux x64<br>
Target machine: CentOS 6 and CentOS 7</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">yum module does not respect disablerepo and enablerepo while querying the RPM packages (repoquery)<br>
If one of the repos, whose enabled is set to 1 in /etc/yum.repos.d/, is temporarily unavailable, even it's has been listed in disablerepo argument, yum module will still fail.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">Fresh install a CentOS 7, then intentionally add a repo config as /etc/yum.repos.d/unavailable.repo</p>
<div class="highlight highlight-source-ini notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="[unavailable]
name=unavailable repo
baseurl=http://localhost/does/not/exist
enabled=1
gpgcheck=0"><pre class="notranslate"><span class="pl-en">[unavailable]</span>
<span class="pl-k">name</span>=unavailable repo
<span class="pl-k">baseurl</span>=http://localhost/does/not/exist
<span class="pl-k">enabled</span>=1
<span class="pl-k">gpgcheck</span>=0</pre></div>
<p dir="auto">Then from control machine, issue the following command for querying packages on CentOS</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible CENTOS7 -vvvv -m yum -a 'disablerepo=* enablerepo=base list=zlib'"><pre class="notranslate"><code class="notranslate">ansible CENTOS7 -vvvv -m yum -a 'disablerepo=* enablerepo=base list=zlib'
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Using /etc/ansible/ansible.cfg as config file
Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/packaging/os/yum.py
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 172.16.3.118 '/bin/sh -c '&quot;'&quot;'( umask 77 &amp;&amp; mkdir -p &quot;` echo ~/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901 `&quot; &amp;&amp; echo ansible-tmp-1490192981.95-117749880161901=&quot;` echo ~/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901 `&quot; ) &amp;&amp; sleep 0'&quot;'&quot;''
&lt;172.16.3.118&gt; PUT /tmp/tmpM2ZNYY TO /root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/yum.py
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 sftp -o BatchMode=no -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[172.16.3.118]'
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 172.16.3.118 '/bin/sh -c '&quot;'&quot;'chmod u+x /root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/ /root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/yum.py &amp;&amp; sleep 0'&quot;'&quot;''
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 172.16.3.118 '/bin/sh -c '&quot;'&quot;'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/yum.py; rm -rf &quot;/root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/&quot; &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'&quot;'&quot;''
172.16.3.118 | SUCCESS =&gt; {
    &quot;changed&quot;: false, 
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;conf_file&quot;: null, 
            &quot;disable_gpg_check&quot;: false, 
            &quot;disablerepo&quot;: &quot;*&quot;, 
            &quot;enablerepo&quot;: &quot;base&quot;, 
            &quot;exclude&quot;: null, 
            &quot;install_repoquery&quot;: true, 
            &quot;list&quot;: &quot;zlib&quot;, 
            &quot;name&quot;: null, 
            &quot;state&quot;: &quot;installed&quot;, 
            &quot;update_cache&quot;: false, 
            &quot;validate_certs&quot;: true
        }, 
        &quot;module_name&quot;: &quot;yum&quot;
    }, 
    &quot;results&quot;: [
        {
            &quot;arch&quot;: &quot;x86_64&quot;, 
            &quot;epoch&quot;: &quot;0&quot;, 
            &quot;name&quot;: &quot;zlib&quot;, 
            &quot;nevra&quot;: &quot;0:zlib-1.2.7-15.el7.x86_64&quot;, 
            &quot;release&quot;: &quot;15.el7&quot;, 
            &quot;repo&quot;: &quot;installed&quot;, 
            &quot;version&quot;: &quot;1.2.7&quot;, 
            &quot;yumstate&quot;: &quot;installed&quot;
        }, 
        {
            &quot;arch&quot;: &quot;i686&quot;, 
            &quot;epoch&quot;: &quot;0&quot;, 
            &quot;name&quot;: &quot;zlib&quot;, 
            &quot;nevra&quot;: &quot;0:zlib-1.2.7-17.el7.i686&quot;, 
            &quot;release&quot;: &quot;17.el7&quot;, 
            &quot;repo&quot;: &quot;base&quot;, 
            &quot;version&quot;: &quot;1.2.7&quot;, 
            &quot;yumstate&quot;: &quot;available&quot;
        }, 
        {
            &quot;arch&quot;: &quot;x86_64&quot;, 
            &quot;epoch&quot;: &quot;0&quot;, 
            &quot;name&quot;: &quot;zlib&quot;, 
            &quot;nevra&quot;: &quot;0:zlib-1.2.7-17.el7.x86_64&quot;, 
            &quot;release&quot;: &quot;17.el7&quot;, 
            &quot;repo&quot;: &quot;base&quot;, 
            &quot;version&quot;: &quot;1.2.7&quot;, 
            &quot;yumstate&quot;: &quot;available&quot;
        }
    ]
}"><pre class="notranslate"><code class="notranslate">Using /etc/ansible/ansible.cfg as config file
Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/packaging/os/yum.py
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 172.16.3.118 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901 `" &amp;&amp; echo ansible-tmp-1490192981.95-117749880161901="` echo ~/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901 `" ) &amp;&amp; sleep 0'"'"''
&lt;172.16.3.118&gt; PUT /tmp/tmpM2ZNYY TO /root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/yum.py
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 sftp -o BatchMode=no -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[172.16.3.118]'
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 172.16.3.118 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/ /root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/yum.py &amp;&amp; sleep 0'"'"''
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 172.16.3.118 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/yum.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/" &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'"'"''
172.16.3.118 | SUCCESS =&gt; {
    "changed": false, 
    "invocation": {
        "module_args": {
            "conf_file": null, 
            "disable_gpg_check": false, 
            "disablerepo": "*", 
            "enablerepo": "base", 
            "exclude": null, 
            "install_repoquery": true, 
            "list": "zlib", 
            "name": null, 
            "state": "installed", 
            "update_cache": false, 
            "validate_certs": true
        }, 
        "module_name": "yum"
    }, 
    "results": [
        {
            "arch": "x86_64", 
            "epoch": "0", 
            "name": "zlib", 
            "nevra": "0:zlib-1.2.7-15.el7.x86_64", 
            "release": "15.el7", 
            "repo": "installed", 
            "version": "1.2.7", 
            "yumstate": "installed"
        }, 
        {
            "arch": "i686", 
            "epoch": "0", 
            "name": "zlib", 
            "nevra": "0:zlib-1.2.7-17.el7.i686", 
            "release": "17.el7", 
            "repo": "base", 
            "version": "1.2.7", 
            "yumstate": "available"
        }, 
        {
            "arch": "x86_64", 
            "epoch": "0", 
            "name": "zlib", 
            "nevra": "0:zlib-1.2.7-17.el7.x86_64", 
            "release": "17.el7", 
            "repo": "base", 
            "version": "1.2.7", 
            "yumstate": "available"
        }
    ]
}
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Using /etc/ansible/ansible.cfg as config file
Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/packaging/os/yum.py
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 172.16.3.118 '/bin/sh -c '&quot;'&quot;'( umask 77 &amp;&amp; mkdir -p &quot;` echo ~/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751 `&quot; &amp;&amp; echo ansible-tmp-1490193076.22-207032486798751=&quot;` echo ~/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751 `&quot; ) &amp;&amp; sleep 0'&quot;'&quot;''
&lt;172.16.3.118&gt; PUT /tmp/tmpuTFEqF TO /root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/yum.py
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 sftp -o BatchMode=no -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[172.16.3.118]'
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 172.16.3.118 '/bin/sh -c '&quot;'&quot;'chmod u+x /root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/ /root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/yum.py &amp;&amp; sleep 0'&quot;'&quot;''
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 172.16.3.118 '/bin/sh -c '&quot;'&quot;'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/yum.py; rm -rf &quot;/root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/&quot; &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'&quot;'&quot;''
172.16.3.118 | FAILED! =&gt; {
    &quot;changed&quot;: false, 
    &quot;failed&quot;: true, 
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;conf_file&quot;: null, 
            &quot;disable_gpg_check&quot;: false, 
            &quot;disablerepo&quot;: &quot;*&quot;, 
            &quot;enablerepo&quot;: &quot;base&quot;, 
            &quot;exclude&quot;: null, 
            &quot;install_repoquery&quot;: true, 
            &quot;list&quot;: &quot;zlib&quot;, 
            &quot;name&quot;: null, 
            &quot;state&quot;: &quot;installed&quot;, 
            &quot;update_cache&quot;: false, 
            &quot;validate_certs&quot;: true
        }, 
        &quot;module_name&quot;: &quot;yum&quot;
    }, 
    &quot;msg&quot;: &quot;Error from repoquery: ['/usr/bin/repoquery', '--show-duplicates', '--plugins', '--quiet', '--disablerepo', '', '--enablerepo', '', '--qf', '%{name}|%{epoch}|%{version}|%{release}|%{arch}|%{repoid}', 'zlib']: Could not match packages: failure: repodata/repomd.xml from unavailable: [Errno 256] No more mirrors to try.\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \&quot;Failed connect to localhost:80; Connection refused\&quot;\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \&quot;Failed connect to localhost:80; Connection refused\&quot;\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \&quot;Failed connect to localhost:80; Connection refused\&quot;\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \&quot;Failed connect to localhost:80; Connection refused\&quot;\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \&quot;Failed connect to localhost:80; Connection refused\&quot;\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \&quot;Failed connect to localhost:80; Connection refused\&quot;\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \&quot;Failed connect to localhost:80; Connection refused\&quot;\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \&quot;Failed connect to localhost:80; Connection refused\&quot;\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \&quot;Failed connect to localhost:80; Connection refused\&quot;\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \&quot;Failed connect to localhost:80; Connection refused\&quot;\n&quot;"><pre class="notranslate"><code class="notranslate">Using /etc/ansible/ansible.cfg as config file
Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc
Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/packaging/os/yum.py
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 172.16.3.118 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751 `" &amp;&amp; echo ansible-tmp-1490193076.22-207032486798751="` echo ~/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751 `" ) &amp;&amp; sleep 0'"'"''
&lt;172.16.3.118&gt; PUT /tmp/tmpuTFEqF TO /root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/yum.py
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 sftp -o BatchMode=no -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[172.16.3.118]'
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 172.16.3.118 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/ /root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/yum.py &amp;&amp; sleep 0'"'"''
&lt;172.16.3.118&gt; ESTABLISH SSH CONNECTION FOR USER: root
&lt;172.16.3.118&gt; SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt 172.16.3.118 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/yum.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/" &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'"'"''
172.16.3.118 | FAILED! =&gt; {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "conf_file": null, 
            "disable_gpg_check": false, 
            "disablerepo": "*", 
            "enablerepo": "base", 
            "exclude": null, 
            "install_repoquery": true, 
            "list": "zlib", 
            "name": null, 
            "state": "installed", 
            "update_cache": false, 
            "validate_certs": true
        }, 
        "module_name": "yum"
    }, 
    "msg": "Error from repoquery: ['/usr/bin/repoquery', '--show-duplicates', '--plugins', '--quiet', '--disablerepo', '', '--enablerepo', '', '--qf', '%{name}|%{epoch}|%{version}|%{release}|%{arch}|%{repoid}', 'zlib']: Could not match packages: failure: repodata/repomd.xml from unavailable: [Errno 256] No more mirrors to try.\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \"Failed connect to localhost:80; Connection refused\"\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \"Failed connect to localhost:80; Connection refused\"\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \"Failed connect to localhost:80; Connection refused\"\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \"Failed connect to localhost:80; Connection refused\"\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \"Failed connect to localhost:80; Connection refused\"\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \"Failed connect to localhost:80; Connection refused\"\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \"Failed connect to localhost:80; Connection refused\"\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \"Failed connect to localhost:80; Connection refused\"\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \"Failed connect to localhost:80; Connection refused\"\nhttp://localhost/does/not/exist/repodata/repomd.xml: [Errno 14] curl#7 - \"Failed connect to localhost:80; Connection refused\"\n"
</code></pre></div>
<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.2.1.0"><pre class="notranslate"><code class="notranslate">ansible 2.2.1.0
</code></pre></div>
<p dir="auto">and</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.0 (devel db8fd95d68) last updated 2017/02/06 16:21:29 (GMT +200)"><pre class="notranslate"><code class="notranslate">ansible 2.3.0 (devel db8fd95d68) last updated 2017/02/06 16:21:29 (GMT +200)
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">nothing special</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Running on macOS 10.12 against SLES-12.2</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">My playbook adds line(s) to a config file.<br>
The line(s) looks like a python or json dictionary.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">dest file on server:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="instances = [
{&quot;port&quot; : 12184, &quot;instance&quot; : &quot;zookeeper-2184&quot;},
{&quot;port&quot; : 12183, &quot;instance&quot; : &quot;zookeeper-2183&quot;},
{&quot;port&quot; : 12182, &quot;instance&quot; : &quot;zookeeper-2182&quot;},
{&quot;port&quot; : 12181, &quot;instance&quot; : &quot;zookeeper-2181&quot;},
]"><pre class="notranslate"><code class="notranslate">instances = [
{"port" : 12184, "instance" : "zookeeper-2184"},
{"port" : 12183, "instance" : "zookeeper-2183"},
{"port" : 12182, "instance" : "zookeeper-2182"},
{"port" : 12181, "instance" : "zookeeper-2181"},
]
</code></pre></div>
<p dir="auto">Playbook to show the bug</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
- hosts: testserver
  remote_user: root
  vars:
    - ZOOKEEPERPORT: 2222
    - bla: abc
  tasks:
  
  - name: add line to config - integer variable
    lineinfile: 
      dest: /root/test_jolokia.cfg
      line: &quot;{\&quot;port\&quot; : 1{{ ZOOKEEPERPORT }}, \&quot;instance\&quot; : \&quot;zookeeper-{{ ZOOKEEPERPORT }}\&quot;},&quot; 
      state: present 
      insertafter: &quot;^instances = &quot;

  - name: add line to config - string variable
    lineinfile: 
      dest: /root/test_jolokia.cfg
      line: &quot;{\&quot;port\&quot; : 1{{ bla }}, \&quot;instance\&quot; : \&quot;zookeeper-{{ bla }}\&quot;},&quot; 
      state: present 
      insertafter: &quot;^instances = &quot;

  - name: add line to config - fixed string
    lineinfile: 
      dest: /root/test_jolokia.cfg
      line: &quot;{\&quot;port\&quot; : 11111, \&quot;instance\&quot; : \&quot;zookeeper-1111\&quot;},&quot; 
      state: present 
      insertafter: &quot;^instances = &quot;"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">testserver</span>
  <span class="pl-ent">remote_user</span>: <span class="pl-s">root</span>
  <span class="pl-ent">vars</span>:
    - <span class="pl-ent">ZOOKEEPERPORT</span>: <span class="pl-c1">2222</span>
    - <span class="pl-ent">bla</span>: <span class="pl-s">abc</span>
  <span class="pl-ent">tasks</span>:
  
  - <span class="pl-ent">name</span>: <span class="pl-s">add line to config - integer variable</span>
    <span class="pl-ent">lineinfile</span>: 
      <span class="pl-ent">dest</span>: <span class="pl-s">/root/test_jolokia.cfg</span>
      <span class="pl-ent">line</span>: <span class="pl-s"><span class="pl-pds">"</span>{<span class="pl-cce">\"</span>port<span class="pl-cce">\"</span> : 1{{ ZOOKEEPERPORT }}, <span class="pl-cce">\"</span>instance<span class="pl-cce">\"</span> : <span class="pl-cce">\"</span>zookeeper-{{ ZOOKEEPERPORT }}<span class="pl-cce">\"</span>},<span class="pl-pds">"</span></span> 
      <span class="pl-ent">state</span>: <span class="pl-s">present </span>
      <span class="pl-ent">insertafter</span>: <span class="pl-s"><span class="pl-pds">"</span>^instances = <span class="pl-pds">"</span></span>

  - <span class="pl-ent">name</span>: <span class="pl-s">add line to config - string variable</span>
    <span class="pl-ent">lineinfile</span>: 
      <span class="pl-ent">dest</span>: <span class="pl-s">/root/test_jolokia.cfg</span>
      <span class="pl-ent">line</span>: <span class="pl-s"><span class="pl-pds">"</span>{<span class="pl-cce">\"</span>port<span class="pl-cce">\"</span> : 1{{ bla }}, <span class="pl-cce">\"</span>instance<span class="pl-cce">\"</span> : <span class="pl-cce">\"</span>zookeeper-{{ bla }}<span class="pl-cce">\"</span>},<span class="pl-pds">"</span></span> 
      <span class="pl-ent">state</span>: <span class="pl-s">present </span>
      <span class="pl-ent">insertafter</span>: <span class="pl-s"><span class="pl-pds">"</span>^instances = <span class="pl-pds">"</span></span>

  - <span class="pl-ent">name</span>: <span class="pl-s">add line to config - fixed string</span>
    <span class="pl-ent">lineinfile</span>: 
      <span class="pl-ent">dest</span>: <span class="pl-s">/root/test_jolokia.cfg</span>
      <span class="pl-ent">line</span>: <span class="pl-s"><span class="pl-pds">"</span>{<span class="pl-cce">\"</span>port<span class="pl-cce">\"</span> : 11111, <span class="pl-cce">\"</span>instance<span class="pl-cce">\"</span> : <span class="pl-cce">\"</span>zookeeper-1111<span class="pl-cce">\"</span>},<span class="pl-pds">"</span></span> 
      <span class="pl-ent">state</span>: <span class="pl-s">present </span>
      <span class="pl-ent">insertafter</span>: <span class="pl-s"><span class="pl-pds">"</span>^instances = <span class="pl-pds">"</span></span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">There should be 3 additional lines like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="instances = [
{&quot;port&quot; : 11111, &quot;instance&quot; : &quot;zookeeper-1111&quot;},
{&quot;port&quot; : 1abc, &quot;instance&quot; : &quot;zookeeper-abc&quot;},
{&quot;port&quot; : 12222, &quot;instance&quot; : &quot;zookeeper-2222&quot;},
{&quot;port&quot; : 12184, &quot;instance&quot; : &quot;zookeeper-2184&quot;},
{&quot;port&quot; : 12183, &quot;instance&quot; : &quot;zookeeper-2183&quot;},
{&quot;port&quot; : 12182, &quot;instance&quot; : &quot;zookeeper-2182&quot;},
{&quot;port&quot; : 12181, &quot;instance&quot; : &quot;zookeeper-2181&quot;},
]"><pre class="notranslate"><code class="notranslate">instances = [
{"port" : 11111, "instance" : "zookeeper-1111"},
{"port" : 1abc, "instance" : "zookeeper-abc"},
{"port" : 12222, "instance" : "zookeeper-2222"},
{"port" : 12184, "instance" : "zookeeper-2184"},
{"port" : 12183, "instance" : "zookeeper-2183"},
{"port" : 12182, "instance" : "zookeeper-2182"},
{"port" : 12181, "instance" : "zookeeper-2181"},
]
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">The line with the integer variable is converted to a list with one dictionary item and then added to the file:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="instances = [
{&quot;port&quot; : 11111, &quot;instance&quot; : &quot;zookeeper-1111&quot;},
{&quot;port&quot; : 1abc, &quot;instance&quot; : &quot;zookeeper-abc&quot;},
[{'instance': 'zookeeper-2222', 'port': 12222}]
{&quot;port&quot; : 12184, &quot;instance&quot; : &quot;zookeeper-2184&quot;},
{&quot;port&quot; : 12183, &quot;instance&quot; : &quot;zookeeper-2183&quot;},
{&quot;port&quot; : 12182, &quot;instance&quot; : &quot;zookeeper-2182&quot;},
{&quot;port&quot; : 12181, &quot;instance&quot; : &quot;zookeeper-2181&quot;},
]"><pre class="notranslate"><code class="notranslate">instances = [
{"port" : 11111, "instance" : "zookeeper-1111"},
{"port" : 1abc, "instance" : "zookeeper-abc"},
[{'instance': 'zookeeper-2222', 'port': 12222}]
{"port" : 12184, "instance" : "zookeeper-2184"},
{"port" : 12183, "instance" : "zookeeper-2183"},
{"port" : 12182, "instance" : "zookeeper-2182"},
{"port" : 12181, "instance" : "zookeeper-2181"},
]
</code></pre></div>
<p dir="auto">In the output of ansible-playbook -vvv the three lines appear as:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[...]
&quot;line&quot;: &quot;[{'instance': 'zookeeper-2222', 'port': 12222}]&quot;, 
[...]
&quot;line&quot;: &quot;{\&quot;port\&quot; : 1abc, \&quot;instance\&quot; : \&quot;zookeeper-abc\&quot;},&quot;, 
[...]
&quot;line&quot;: &quot;{\&quot;port\&quot; : 11111, \&quot;instance\&quot; : \&quot;zookeeper-1111\&quot;},&quot;, 
[...]"><pre class="notranslate"><code class="notranslate">[...]
"line": "[{'instance': 'zookeeper-2222', 'port': 12222}]", 
[...]
"line": "{\"port\" : 1abc, \"instance\" : \"zookeeper-abc\"},", 
[...]
"line": "{\"port\" : 11111, \"instance\" : \"zookeeper-1111\"},", 
[...]
</code></pre></div>
<h5 dir="auto">WORKAROUND</h5>
<p dir="auto">My workaround is to add one space to the beginning of the line, then it works as it should:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
[...]
  - name: add line to config - integer variable
    lineinfile: 
      dest: /root/test_jolokia.cfg
      line: &quot; {\&quot;port\&quot; : 1{{ ZOOKEEPERPORT }}, \&quot;instance\&quot; : \&quot;zookeeper-{{ ZOOKEEPERPORT }}\&quot;},&quot; 
      state: present 
      insertafter: &quot;^instances = &quot;
[...]"><pre class="notranslate">---
<span class="pl-s">[...]</span>
  - <span class="pl-ent">name</span>: <span class="pl-s">add line to config - integer variable</span>
    <span class="pl-ent">lineinfile</span>: 
      <span class="pl-ent">dest</span>: <span class="pl-s">/root/test_jolokia.cfg</span>
      <span class="pl-ent">line</span>: <span class="pl-s"><span class="pl-pds">"</span> {<span class="pl-cce">\"</span>port<span class="pl-cce">\"</span> : 1{{ ZOOKEEPERPORT }}, <span class="pl-cce">\"</span>instance<span class="pl-cce">\"</span> : <span class="pl-cce">\"</span>zookeeper-{{ ZOOKEEPERPORT }}<span class="pl-cce">\"</span>},<span class="pl-pds">"</span></span> 
      <span class="pl-ent">state</span>: <span class="pl-s">present </span>
      <span class="pl-ent">insertafter</span>: <span class="pl-s"><span class="pl-pds">"</span>^instances = <span class="pl-pds">"</span></span>
<span class="pl-s">[...]</span></pre></div>
<p dir="auto">dest file:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="instances = [
{&quot;port&quot; : 11111, &quot;instance&quot; : &quot;zookeeper-1111&quot;},
{&quot;port&quot; : 1abc, &quot;instance&quot; : &quot;zookeeper-abc&quot;},
 {&quot;port&quot; : 12222, &quot;instance&quot; : &quot;zookeeper-2222&quot;},
{&quot;port&quot; : 12184, &quot;instance&quot; : &quot;zookeeper-2184&quot;},
{&quot;port&quot; : 12183, &quot;instance&quot; : &quot;zookeeper-2183&quot;},
{&quot;port&quot; : 12182, &quot;instance&quot; : &quot;zookeeper-2182&quot;},
{&quot;port&quot; : 12181, &quot;instance&quot; : &quot;zookeeper-2181&quot;},
]"><pre class="notranslate"><code class="notranslate">instances = [
{"port" : 11111, "instance" : "zookeeper-1111"},
{"port" : 1abc, "instance" : "zookeeper-abc"},
 {"port" : 12222, "instance" : "zookeeper-2222"},
{"port" : 12184, "instance" : "zookeeper-2184"},
{"port" : 12183, "instance" : "zookeeper-2183"},
{"port" : 12182, "instance" : "zookeeper-2182"},
{"port" : 12181, "instance" : "zookeeper-2181"},
]
</code></pre></div>
<p dir="auto">The fixed line in verbose output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;line&quot;: &quot; {\&quot;port\&quot; : 12222, \&quot;instance\&quot; : \&quot;zookeeper-2222\&quot;},&quot;,"><pre class="notranslate"><code class="notranslate">"line": " {\"port\" : 12222, \"instance\" : \"zookeeper-2222\"},",
</code></pre></div>