Issue 1:
This is a duplicate of #24110 but that issue is closed and nobody seems to be willing to open it (I even asked in #ansible).

ISSUE TYPE

Bug Report

COMPONENT NAME

pacman

ANSIBLE VERSION

ansible-playbook 2.4.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/thom/.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-playbook
python version = 2.7.14 (default, Sep 20 2017, 01:25:59) [GCC 7.2.0]

CONFIGURATION

N/A

OS / ENVIRONMENT

Arch Linux

SUMMARY

Pacman supports aliases when searching or installing package names, but doesn't support them when querying package's installed states. This crashes the Ansible pacman module.

STEPS TO REPRODUCE

- hosts: localhost
become: yes
tasks:
- pacman: name=svn state=present

EXPECTED RESULTS

Show that subversion is already installed

ACTUAL RESULTS

task path: /home/thom/git/ansible/test.yml:4
Using module file /usr/lib/python2.7/site-packages/ansible/modules/packaging/os/pacman.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: thom
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/thom/.ansible/tmp/ansible-tmp-1510228510.14-193730463357425 `" && echo ansible-tmp-1510228510.14-193730463357425="` echo /home/thom/.ansible/tmp/ansible-tmp-1510228510.14-193730463357425 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmpO43qZY TO /home/thom/.ansible/tmp/ansible-tmp-1510228510.14-193730463357425/pacman.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/thom/.ansible/tmp/ansible-tmp-1510228510.14-193730463357425/ /home/thom/.ansible/tmp/ansible-tmp-1510228510.14-193730463357425/pacman.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S -p "[sudo via ansible, key=piygkrwrgcualemppeyqvtcebrddppaq] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-piygkrwrgcualemppeyqvtcebrddppaq; /usr/bin/python2 /home/thom/.ansible/tmp/ansible-tmp-1510228510.14-193730463357425/pacman.py; rm -rf "/home/thom/.ansible/tmp/ansible-tmp-1510228510.14-193730463357425/" > /dev/null 2>&1'"'"' && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_VEhXK5/ansible_module_pacman.py", line 444, in <module>
main()
File "/tmp/ansible_VEhXK5/ansible_module_pacman.py", line 436, in main
install_packages(module, pacman_path, p['state'], pkgs, pkg_files)
File "/tmp/ansible_VEhXK5/ansible_module_pacman.py", line 298, in install_packages
data = stdout.split('\n')[3].split(' ')[2:]
IndexError: list index out of range

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_VEhXK5/ansible_module_pacman.py\", line 444, in <module>\n main()\n File \"/tmp/ansible_VEhXK5/ansible_module_pacman.py\", line 436, in main\n install_packages(module, pacman_path, p['state'], pkgs, pkg_files)\n File \"/tmp/ansible_VEhXK5/ansible_module_pacman.py\", line 298, in install_packages\n data = stdout.split('\\n')[3].split(' ')[2:]\nIndexError: list index out of range\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

See also #24110

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

pacman module

ANSIBLE VERSION

ansible 2.3.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.13 (default, Feb 11 2017, 12:22:40) [GCC 6.3.1 20170109]

This worked fine in Ansible 2.2.

CONFIGURATION

[defaults]
nocows=1

OS / ENVIRONMENT

I'm running on Arch Linux

SUMMARY

Running

STEPS TO REPRODUCE

https://github.com/thomwiggers/odroid-playbooks/blob/master/roles/common/tasks/common.yml#L8-L16

EXPECTED RESULTS

Updated/installed packages

ACTUAL RESULTS

Crashes.

TASK [common : Install packages] ************************************************************************************************************************************************************************************************************
task path: /home/thom/git/stage/management/roles/common/tasks/common.yml:8
Using module file /usr/lib/python2.7/site-packages/ansible/modules/packaging/os/pacman.py
<homer> ESTABLISH SSH CONNECTION FOR USER: None
<homer> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/thom/.ansible/cp/fdc2bea664 homer '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<homer> (0, '/home/thom\n', "OpenSSH_7.5p1, OpenSSL 1.1.0e 16 Feb 2017\r\ndebug1: Reading configuration data /home/thom/.ssh/config\r\ndebug1: /home/thom/.ssh/config line 3: Applying options for *\r\ndebug3: kex names ok: [curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256]\r\ndebug1: /home/thom/.ssh/config line 82: Applying options for homer\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: Setting implicit ProxyCommand from ProxyJump: ssh -l twiggers -vvv -W '[%h]:%p' lilo.science.ru.nl\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 7302\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n")
<homer> ESTABLISH SSH CONNECTION FOR USER: None
<homer> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/thom/.ansible/cp/fdc2bea664 homer '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /home/thom/.ansible/tmp/ansible-tmp-1493382410.32-244000386629474 `" && echo ansible-tmp-1493382410.32-244000386629474="` echo /home/thom/.ansible/tmp/ansible-tmp-1493382410.32-244000386629474 `" ) && sleep 0'"'"''
<homer> (0, 'ansible-tmp-1493382410.32-244000386629474=/home/thom/.ansible/tmp/ansible-tmp-1493382410.32-244000386629474\n', "OpenSSH_7.5p1, OpenSSL 1.1.0e 16 Feb 2017\r\ndebug1: Reading configuration data /home/thom/.ssh/config\r\ndebug1: /home/thom/.ssh/config line 3: Applying options for *\r\ndebug3: kex names ok: [curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256]\r\ndebug1: /home/thom/.ssh/config line 82: Applying options for homer\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: Setting implicit ProxyCommand from ProxyJump: ssh -l twiggers -vvv -W '[%h]:%p' lilo.science.ru.nl\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 7302\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n")
<homer> PUT /tmp/tmp3nwsZr TO /home/thom/.ansible/tmp/ansible-tmp-1493382410.32-244000386629474/pacman.py
<homer> SSH: EXEC sftp -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/thom/.ansible/cp/fdc2bea664 '[homer]'
<homer> (0, 'sftp> put /tmp/tmp3nwsZr /home/thom/.ansible/tmp/ansible-tmp-1493382410.32-244000386629474/pacman.py\n', 'OpenSSH_7.5p1, OpenSSL 1.1.0e 16 Feb 2017\r\ndebug1: Reading configuration data /home/thom/.ssh/config\r\ndebug1: /home/thom/.ssh/config line 3: Applying options for *\r\ndebug3: kex names ok: [curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256]\r\ndebug1: /home/thom/.ssh/config line 82: Applying options for homer\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: Setting implicit ProxyCommand from ProxyJump: ssh -l twiggers -vvv -W \'[%h]:%p\' lilo.science.ru.nl\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 7302\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug2: Remote version: 3\r\ndebug2: Server supports extension "posix-rename@openssh.com" revision 1\r\ndebug2: Server supports extension "statvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "fstatvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "hardlink@openssh.com" revision 1\r\ndebug2: Server supports extension "fsync@openssh.com" revision 1\r\ndebug3: Sent message fd 5 T:16 I:1\r\ndebug3: SSH_FXP_REALPATH . -> /home/thom size 0\r\ndebug3: Looking up /tmp/tmp3nwsZr\r\ndebug3: Sent message fd 5 T:17 I:2\r\ndebug3: Received stat reply T:101 I:2\r\ndebug1: Couldn\'t stat remote file: No such file or directory\r\ndebug3: Sent message SSH2_FXP_OPEN I:3 P:/home/thom/.ansible/tmp/ansible-tmp-1493382410.32-244000386629474/pacman.py\r\ndebug3: Sent message SSH2_FXP_WRITE I:4 O:0 S:32768\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 4 32768 bytes at 0\r\ndebug3: Sent message SSH2_FXP_WRITE I:5 O:32768 S:27437\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 5 27437 bytes at 32768\r\ndebug3: Sent message SSH2_FXP_CLOSE I:4\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<homer> ESTABLISH SSH CONNECTION FOR USER: None
<homer> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/thom/.ansible/cp/fdc2bea664 homer '/bin/sh -c '"'"'chmod u+x /home/thom/.ansible/tmp/ansible-tmp-1493382410.32-244000386629474/ /home/thom/.ansible/tmp/ansible-tmp-1493382410.32-244000386629474/pacman.py && sleep 0'"'"''
<homer> (0, '', "OpenSSH_7.5p1, OpenSSL 1.1.0e 16 Feb 2017\r\ndebug1: Reading configuration data /home/thom/.ssh/config\r\ndebug1: /home/thom/.ssh/config line 3: Applying options for *\r\ndebug3: kex names ok: [curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256]\r\ndebug1: /home/thom/.ssh/config line 82: Applying options for homer\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: Setting implicit ProxyCommand from ProxyJump: ssh -l twiggers -vvv -W '[%h]:%p' lilo.science.ru.nl\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 7302\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n")
<homer> ESTABLISH SSH CONNECTION FOR USER: None
<homer> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/thom/.ansible/cp/fdc2bea664 -tt homer '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-tixkiailijheyhbmsllbeczwqwdaiueq; /usr/bin/python /home/thom/.ansible/tmp/ansible-tmp-1493382410.32-244000386629474/pacman.py; rm -rf "/home/thom/.ansible/tmp/ansible-tmp-1493382410.32-244000386629474/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && sleep 0'"'"''
<homer> (0, 'Traceback (most recent call last):\r\n File "/tmp/ansible_nbtluy_z/ansible_module_pacman.py", line 451, in <module>\r\n main()\r\n File "/tmp/ansible_nbtluy_z/ansible_module_pacman.py", line 443, in main\r\n install_packages(module, pacman_path, p[\'state\'], pkgs, pkg_files)\r\n File "/tmp/ansible_nbtluy_z/ansible_module_pacman.py", line 306, in install_packages\r\n data = stdout.split(\'\\n\')[3].split(\' \')[2:]\r\nIndexError: list index out of range\r\n', "OpenSSH_7.5p1, OpenSSL 1.1.0e 16 Feb 2017\r\ndebug1: Reading configuration data /home/thom/.ssh/config\r\ndebug1: /home/thom/.ssh/config line 3: Applying options for *\r\ndebug3: kex names ok: [curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256]\r\ndebug1: /home/thom/.ssh/config line 82: Applying options for homer\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: Setting implicit ProxyCommand from ProxyJump: ssh -l twiggers -vvv -W '[%h]:%p' lilo.science.ru.nl\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 7302\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to 131.174.12.215 closed.\r\n")
failed: [homer] (item=[u'ack', u'base-devel', u'clang', u'cmake', u'cronie', u'curl', u'git', u'htop', u'ltrace', u'ntp', u'openbsd-netcat', u'python', u'python-pip', u'python-virtualenv', u'python-virtualenvwrapper', u'python2', u'python2-pip', u'rsync', u'strace', u'svn', u'the_silver_searcher', u'tmux', u'valgrind', u'vim', u'wget', u'zsh']) => {
"failed": true,
"item": [
"ack",
"base-devel",
"clang",
"cmake",
"cronie",
"curl",
"git",
"htop",
"ltrace",
"ntp",
"openbsd-netcat",
"python",
"python-pip",
"python-virtualenv",
"python-virtualenvwrapper",
"python2",
"python2-pip",
"rsync",
"strace",
"svn",
"the_silver_searcher",
"tmux",
"valgrind",
"vim",
"wget",
"zsh"
],
"module_stderr": "OpenSSH_7.5p1, OpenSSL 1.1.0e 16 Feb 2017\r\ndebug1: Reading configuration data /home/thom/.ssh/config\r\ndebug1: /home/thom/.ssh/config line 3: Applying options for *\r\ndebug3: kex names ok: [curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256]\r\ndebug1: /home/thom/.ssh/config line 82: Applying options for homer\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: Setting implicit ProxyCommand from ProxyJump: ssh -l twiggers -vvv -W '[%h]:%p' lilo.science.ru.nl\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 7302\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to 131.174.12.215 closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_nbtluy_z/ansible_module_pacman.py\", line 451, in <module>\r\n main()\r\n File \"/tmp/ansible_nbtluy_z/ansible_module_pacman.py\", line 443, in main\r\n install_packages(module, pacman_path, p['state'], pkgs, pkg_files)\r\n File \"/tmp/ansible_nbtluy_z/ansible_module_pacman.py\", line 306, in install_packages\r\n data = stdout.split('\\n')[3].split(' ')[2:]\r\nIndexError: list index out of range\r\n",
"msg": "MODULE FAILURE",
"rc": 0
}