Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

yum

ANSIBLE VERSION

ansible 2.2.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

No changes to ansible.cfg, and no ANSIBLE_* environment variables are set

OS / ENVIRONMENT

Control machine: Arch Linux x64

Target machine: CentOS 6 and CentOS 7

SUMMARY

yum module does not respect disablerepo and enablerepo while querying the RPM packages (repoquery)

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.

STEPS TO REPRODUCE

Fresh install a CentOS 7, then intentionally add a repo config as /etc/yum.repos.d/unavailable.repo

[unavailable]
name=unavailable repo
baseurl=http://localhost/does/not/exist
enabled=1
gpgcheck=0

Then from control machine, issue the following command for querying packages on CentOS

ansible CENTOS7 -vvvv -m yum -a 'disablerepo=* enablerepo=base list=zlib'

EXPECTED RESULTS

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
<172.16.3.118> ESTABLISH SSH CONNECTION FOR USER: root
<172.16.3.118> 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 && mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901 `" && echo ansible-tmp-1490192981.95-117749880161901="` echo ~/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901 `" ) && sleep 0'"'"''
<172.16.3.118> PUT /tmp/tmpM2ZNYY TO /root/.ansible/tmp/ansible-tmp-1490192981.95-117749880161901/yum.py
<172.16.3.118> 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]'
<172.16.3.118> ESTABLISH SSH CONNECTION FOR USER: root
<172.16.3.118> 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 && sleep 0'"'"''
<172.16.3.118> ESTABLISH SSH CONNECTION FOR USER: root
<172.16.3.118> 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/" > /dev/null 2>&1 && sleep 0'"'"''
172.16.3.118 | SUCCESS => {
"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"
}
]
}

ACTUAL RESULTS

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
<172.16.3.118> ESTABLISH SSH CONNECTION FOR USER: root
<172.16.3.118> 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 && mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751 `" && echo ansible-tmp-1490193076.22-207032486798751="` echo ~/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751 `" ) && sleep 0'"'"''
<172.16.3.118> PUT /tmp/tmpuTFEqF TO /root/.ansible/tmp/ansible-tmp-1490193076.22-207032486798751/yum.py
<172.16.3.118> 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]'
<172.16.3.118> ESTABLISH SSH CONNECTION FOR USER: root
<172.16.3.118> 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 && sleep 0'"'"''
<172.16.3.118> ESTABLISH SSH CONNECTION FOR USER: root
<172.16.3.118> 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/" > /dev/null 2>&1 && sleep 0'"'"''
172.16.3.118 | FAILED! => {
"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"

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

lineinfile

ANSIBLE VERSION

ansible 2.2.1.0

and

ansible 2.3.0 (devel db8fd95d68) last updated 2017/02/06 16:21:29 (GMT +200)

CONFIGURATION

nothing special

OS / ENVIRONMENT

Running on macOS 10.12 against SLES-12.2

SUMMARY

My playbook adds line(s) to a config file.

The line(s) looks like a python or json dictionary.

STEPS TO REPRODUCE

dest file on server:

instances = [
{"port" : 12184, "instance" : "zookeeper-2184"},
{"port" : 12183, "instance" : "zookeeper-2183"},
{"port" : 12182, "instance" : "zookeeper-2182"},
{"port" : 12181, "instance" : "zookeeper-2181"},
]

Playbook to show the bug

---
- 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: "{\"port\" : 1{{ ZOOKEEPERPORT }}, \"instance\" : \"zookeeper-{{ ZOOKEEPERPORT }}\"},"
state: present
insertafter: "^instances = "

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

- name: add line to config - fixed string
lineinfile:
dest: /root/test_jolokia.cfg
line: "{\"port\" : 11111, \"instance\" : \"zookeeper-1111\"},"
state: present
insertafter: "^instances = "

EXPECTED RESULTS

There should be 3 additional lines like:

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"},
]

ACTUAL RESULTS

The line with the integer variable is converted to a list with one dictionary item and then added to the file:

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"},
]

In the output of ansible-playbook -vvv the three lines appear as:

[...]
"line": "[{'instance': 'zookeeper-2222', 'port': 12222}]",
[...]
"line": "{\"port\" : 1abc, \"instance\" : \"zookeeper-abc\"},",
[...]
"line": "{\"port\" : 11111, \"instance\" : \"zookeeper-1111\"},",
[...]

WORKAROUND

My workaround is to add one space to the beginning of the line, then it works as it should:

---
[...]
- name: add line to config - integer variable
lineinfile:
dest: /root/test_jolokia.cfg
line: " {\"port\" : 1{{ ZOOKEEPERPORT }}, \"instance\" : \"zookeeper-{{ ZOOKEEPERPORT }}\"},"
state: present
insertafter: "^instances = "
[...]

dest file:

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"},
]

The fixed line in verbose output:

"line": " {\"port\" : 12222, \"instance\" : \"zookeeper-2222\"},",