Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

authorized_key

ANSIBLE VERSION

ansible 2.2.1.0
config file = /Users/brian/Dropbox/Tech-Notes/Programming/Ansible/ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

[defaults]
inventory = inventory
remote_user = ubuntu
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
roles_path = roles
retry_files_enabled = False

OS / ENVIRONMENT

macOS Sierra (10.12.3)

SUMMARY

Today I had to use one of my playbooks against a box that only has Python3. I learned about the "ansible_python_interpreter=/usr/bin/python3" variable I had to set, and my playbook worked through everything until I got to the "authorized_key" where it failed. I tried the same playbook against an Ubuntu box that still has Python2.7 and it worked fine. So it seems to be only the Python3.

STEPS TO REPRODUCE

- name: Add SSH keys for the administrators
authorized_key:
user: bhuddleston
key: https://github.com/bhuddleston.keys
state: present

EXPECTED RESULTS

TASK [Add SSH keys for the administrators] *************************************

changed: [targethost.domain.net]

ACTUAL RESULTS

The module gave an error and didn't add the SSH keys to the user.

{
"changed": false,
"failed": true,
"module_stderr": "Shared connection to collector.oitd.net closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible__ftramx6/ansible_module_authorized_key.py\", line 527, in <module>\r\n main()\r\n File \"/tmp/ansible__ftramx6/ansible_module_authorized_key.py\", line 523, in main\r\n results = enforce_state(module, module.params)\r\n File \"/tmp/ansible__ftramx6/ansible_module_authorized_key.py\", line 433, in enforce_state\r\n key = [s for s in key.splitlines() if s and not s.startswith('#')]\r\n File \"/tmp/ansible__ftramx6/ansible_module_authorized_key.py\", line 433, in <listcomp>\r\n key = [s for s in key.splitlines() if s and not s.startswith('#')]\r\nTypeError: startswith first arg must be bytes or a tuple of bytes, not str\r\n",
"msg": "MODULE FAILURE"
}

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

authorized_key core module

ANSIBLE VERSION

ansible 2.2.0.0
config file = /home/james/active/boss/ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

[defaults]

nocows=1

inventory=ansible_hosts

host_key_checking=False

OS / ENVIRONMENT

Local: Ubuntu with Python 3.5.0+ at /usr/bin/python3.5

Remote: Ubuntu 16.04.1 with Python 3.5.2 at /usr/bin/python3.5

Python version is specified with:

ansible_python_interpreter=/usr/bin/python3.5

SUMMARY

STEPS TO REPRODUCE

Given that user james exists, attempt to install keys from https://github.com/jamescooke.keys using authorized_key module.

Smallest example playbook I could create test.yml:

---
- hosts: all
vars:
- ansible_ssh_user: root
tasks:
- authorized_key:
user: james
key: https://github.com/jamescooke.keys

EXPECTED RESULTS

Two keys would be added to james user on remote.

ACTUAL RESULTS

Python crashes.

(venv) james@codebox:~/active/boss$ ansible-playbook test.yml -vvvv
Using /home/james/active/boss/ansible.cfg as config file
Loading callback plugin default of type stdout, v2.0 from /home/james/active/boss/venv/lib/python3.5/site-packages/ansible/plugins/callback/__init__.py

PLAYBOOK: test.yml *************************************************************
1 plays in test.yml

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
Using module file /home/james/active/boss/venv/lib/python3.5/site-packages/ansible/modules/core/system/setup.py
<104.131.17.109> ESTABLISH SSH CONNECTION FOR USER: root
<104.131.17.109> 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 User=root -o ConnectTimeout=10 -o ControlPath=/home/james/.ansible/cp/ansible-ssh-%h-%p-%r 104.131.17.109 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1483808135.2190897-90788529272429 `" && echo ansible-tmp-1483808135.2190897-90788529272429="` echo $HOME/.ansible/tmp/ansible-tmp-1483808135.2190897-90788529272429 `" ) && sleep 0'"'"''
<104.131.17.109> PUT /tmp/tmpqi9xuich TO /root/.ansible/tmp/ansible-tmp-1483808135.2190897-90788529272429/setup.py
<104.131.17.109> 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 User=root -o ConnectTimeout=10 -o ControlPath=/home/james/.ansible/cp/ansible-ssh-%h-%p-%r '[104.131.17.109]'
<104.131.17.109> ESTABLISH SSH CONNECTION FOR USER: root
<104.131.17.109> 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 User=root -o ConnectTimeout=10 -o ControlPath=/home/james/.ansible/cp/ansible-ssh-%h-%p-%r 104.131.17.109 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1483808135.2190897-90788529272429/ /root/.ansible/tmp/ansible-tmp-1483808135.2190897-90788529272429/setup.py && sleep 0'"'"''
<104.131.17.109> ESTABLISH SSH CONNECTION FOR USER: root
<104.131.17.109> 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 User=root -o ConnectTimeout=10 -o ControlPath=/home/james/.ansible/cp/ansible-ssh-%h-%p-%r -tt 104.131.17.109 '/bin/sh -c '"'"'/usr/bin/python3.5 /root/.ansible/tmp/ansible-tmp-1483808135.2190897-90788529272429/setup.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1483808135.2190897-90788529272429/" > /dev/null 2>&1 && sleep 0'"'"''
ok: [104.131.17.109]

TASK [authorized_key] **********************************************************
task path: /home/james/active/boss/test.yml:6
Using module file /home/james/active/boss/venv/lib/python3.5/site-packages/ansible/modules/core/system/authorized_key.py
<104.131.17.109> ESTABLISH SSH CONNECTION FOR USER: root
<104.131.17.109> 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 User=root -o ConnectTimeout=10 -o ControlPath=/home/james/.ansible/cp/ansible-ssh-%h-%p-%r 104.131.17.109 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1483808139.0550506-81997757222281 `" && echo ansible-tmp-1483808139.0550506-81997757222281="` echo $HOME/.ansible/tmp/ansible-tmp-1483808139.0550506-81997757222281 `" ) && sleep 0'"'"''
<104.131.17.109> PUT /tmp/tmpinuhh2o4 TO /root/.ansible/tmp/ansible-tmp-1483808139.0550506-81997757222281/authorized_key.py
<104.131.17.109> 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 User=root -o ConnectTimeout=10 -o ControlPath=/home/james/.ansible/cp/ansible-ssh-%h-%p-%r '[104.131.17.109]'
<104.131.17.109> ESTABLISH SSH CONNECTION FOR USER: root
<104.131.17.109> 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 User=root -o ConnectTimeout=10 -o ControlPath=/home/james/.ansible/cp/ansible-ssh-%h-%p-%r 104.131.17.109 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1483808139.0550506-81997757222281/ /root/.ansible/tmp/ansible-tmp-1483808139.0550506-81997757222281/authorized_key.py && sleep 0'"'"''
<104.131.17.109> ESTABLISH SSH CONNECTION FOR USER: root
<104.131.17.109> 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 User=root -o ConnectTimeout=10 -o ControlPath=/home/james/.ansible/cp/ansible-ssh-%h-%p-%r -tt 104.131.17.109 '/bin/sh -c '"'"'/usr/bin/python3.5 /root/.ansible/tmp/ansible-tmp-1483808139.0550506-81997757222281/authorized_key.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1483808139.0550506-81997757222281/" > /dev/null 2>&1 && sleep 0'"'"''
fatal: [104.131.17.109]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "authorized_key"
},
"module_stderr": "OpenSSH_6.9p1 Ubuntu-2ubuntu0.2, OpenSSL 1.0.2d 9 Jul 2015\r\ndebug1: Reading configuration data /home/james/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\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 = 22341\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 104.131.17.109 closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_grkuvdsh/ansible_module_authorized_key.py\", line 527, in <module>\r\n main()\r\n File \"/tmp/ansible_grkuvdsh/ansible_module_authorized_key.py\", line 523, in main\r\n results = enforce_state(module, module.params)\r\n File \"/tmp/ansible_grkuvdsh/ansible_module_authorized_key.py\", line 433, in enforce_state\r\n key = [s for s in key.splitlines() if s and not s.startswith('#')]\r\n File \"/tmp/ansible_grkuvdsh/ansible_module_authorized_key.py\", line 433, in <listcomp>\r\n key = [s for s in key.splitlines() if s and not s.startswith('#')]\r\nTypeError: startswith first arg must be bytes or a tuple of bytes, not str\r\n",
"msg": "MODULE FAILURE"
}
to retry, use: --limit @/home/james/active/boss/test.retry

PLAY RECAP *********************************************************************
104.131.17.109 : ok=1 changed=0 unreachable=0 failed=1

Fails with:

current master: https://github.com/ansible/ansible/tree/cba66dfedc4b34c622fb61209dbe355d8bcc8503

2.2.0.0 from pip: https://pypi.python.org/pypi/ansible/2.2.0.0