Repository: ansible/ansible

Issue:
rhn_register module reports failure when registering
##### ISSUE TYPE

    Bug Report

##### COMPONENT NAME

    rhn_register.py

##### ANSIBLE VERSION

```
    ansible 2.3.0.0
      config file = /home/ansible/ansible.cfg
      configured module search path = Default w/o overrides
      python version = 2.7.5 (default, Aug  2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
```

##### CONFIGURATION

ansible.cfg

    [defaults]
    inventory = ~/hosts
    roles_path = /home/ansible/code/
    vault_password_file = /home/ansible/.vault_pass.txt
    nocows = 1
    host_key_checking=False
    retry_files_save_path = ~/.ansible/retry-files
    #remote_tmp = /tmp/.ansible/tmp

##### OS / ENVIRONMENT

Ansible server is RHEL 7.3.
Target server is RHEL 7.3.
Satellite server is 5.6.0.

##### SUMMARY

Trying to register a server with the Satellite server using an activation key fails.

##### STEPS TO REPRODUCE

```yaml
    - name: register rhn
      rhn_register: state=present activationkey={{ satellite_activation_key }} profilename={{ ansible_hostname }} server_url="https://{{ satellite_server_FQDN }}/XMLRPC"
```
      
##### EXPECTED RESULTS

The target server should be registered in the Satellite server without error. Ansible should report "changed".

##### ACTUAL RESULTS

I receive the error "cannot marshal None unless allow_none is enabled" when registering clients with a Satellite server. Ansible reports this as a failed task although the target machine is successfully (and correctly) joined to Satellite. Running the task a second time reports "ok" with the message "System already registered.".

The error which appears when running my task with version b3b598c and later:

```
    TASK [satellite-client : register rhn] ***************************************************************************************************************************************************************************
    task path: /home/ansible/satellite-client/tasks/main.yml:15
    Using module file /usr/lib/python2.7/site-packages/ansible/modules/packaging/os/rhn_register.py
    <10.123.123.123> ESTABLISH SSH CONNECTION FOR USER: root
    <10.123.123.123> SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/c2d250d71c 10.123.123.123 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
    <10.123.123.123> (0, '/root\n', 'OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: 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 = 32570\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')
    <10.123.123.123> ESTABLISH SSH CONNECTION FOR USER: root
    <10.123.123.123> SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/c2d250d71c 10.123.123.123 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734 `" && echo ansible-tmp-1495638489.06-58962211270734="` echo /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734 `" ) && sleep 0'"'"''
    <10.123.123.123> (0, 'ansible-tmp-1495638489.06-58962211270734=/root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734\n', 'OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: 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 = 32570\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')
    <10.123.123.123> PUT /tmp/tmpP4VL2c TO /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/rhn_register.py
    <10.123.123.123> SSH: EXEC sshpass -d12 sftp -o BatchMode=no -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/c2d250d71c '[10.123.123.123]'
    <10.123.123.123> (0, 'sftp> put /tmp/tmpP4VL2c /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/rhn_register.py\n', 'OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: 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 = 32570\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 . -> /root size 0\r\ndebug3: Looking up /tmp/tmpP4VL2c\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:/root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/rhn_register.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:31831\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 5 31831 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')
    <10.123.123.123> ESTABLISH SSH CONNECTION FOR USER: root
    <10.123.123.123> SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/c2d250d71c 10.123.123.123 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/ /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/rhn_register.py && sleep 0'"'"''
    <10.123.123.123> (0, '', 'OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: 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 = 32570\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')
    <10.123.123.123> ESTABLISH SSH CONNECTION FOR USER: root
    <10.123.123.123> SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/c2d250d71c -tt 10.123.123.123 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/rhn_register.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/" > /dev/null 2>&1 && sleep 0'"'"''
    <10.123.123.123> (0, '\r\n{"msg": "Failed to register with \'satserver.domain.com\': cannot marshal None unless allow_none is enabled", "failed": true, "invocation": {"module_args": {"username": null, "systemorgid": null, "enable_eus": false, "server_url": "https://satserver.domain.com/XMLRPC", "channels": [], "state": "present", "sslcacert": null, "activationkey": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "profilename": "testserver1", "password": null}}}\r\n', 'OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: 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 = 32570\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 10.123.123.123 closed.\r\n')
    fatal: [10.123.123.123]: FAILED! => {
        "changed": false,
        "failed": true,
        "invocation": {
            "module_args": {
                "activationkey": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "channels": [],
                "enable_eus": false,
                "password": null,
                "profilename": "testserver1",
                "server_url": "https://satserver.domain.com/XMLRPC",
                "sslcacert": null,
                "state": "present",
                "systemorgid": null,
                "username": null
            }
        },
        "msg": "Failed to register with 'satserver.domain.com': cannot marshal None unless allow_none is enabled"
    }
```

##### FURTHER DETAILS

This issue was also reported in https://github.com/ansible/ansible/issues/22300#issuecomment-290036871 but it does not appear to be fixed by any of the changes mentioned in https://github.com/ansible/ansible/issues/22300 or the changes in https://github.com/ansible/ansible/commit/fb6e9e8fbe6c34f10611c92b4d0c481eca44c06d . Because of these details, I believe this to be a distinct issue.

I believe the changes at 7faef2c caused this problem. I have tested numerous versions of rhn_register.py in Ansible 2.3.0.0 to come to this conclusion.

I have created a version of rhn_register.py that resolves the error in Ansible 2.3.0.0: https://gist.github.com/WhyIsThisOpen/d48b9a01b7d658b6ec23fd29ae801ad2
rhn_register module reports failure when registering
##### ISSUE TYPE

    Bug Report

##### COMPONENT NAME

    rhn_register.py

##### ANSIBLE VERSION

```
    ansible 2.3.0.0
      config file = /home/ansible/ansible.cfg
      configured module search path = Default w/o overrides
      python version = 2.7.5 (default, Aug  2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
```

##### CONFIGURATION

ansible.cfg

    [defaults]
    inventory = ~/hosts
    roles_path = /home/ansible/code/
    vault_password_file = /home/ansible/.vault_pass.txt
    nocows = 1
    host_key_checking=False
    retry_files_save_path = ~/.ansible/retry-files
    #remote_tmp = /tmp/.ansible/tmp

##### OS / ENVIRONMENT

Ansible server is RHEL 7.3.
Target server is RHEL 7.3.
Satellite server is 5.6.0.

##### SUMMARY

Trying to register a server with the Satellite server using an activation key fails.

##### STEPS TO REPRODUCE

```yaml
    - name: register rhn
      rhn_register: state=present activationkey={{ satellite_activation_key }} profilename={{ ansible_hostname }} server_url="https://{{ satellite_server_FQDN }}/XMLRPC"
```
      
##### EXPECTED RESULTS

The target server should be registered in the Satellite server without error. Ansible should report "changed".

##### ACTUAL RESULTS

I receive the error "cannot marshal None unless allow_none is enabled" when registering clients with a Satellite server. Ansible reports this as a failed task although the target machine is successfully (and correctly) joined to Satellite. Running the task a second time reports "ok" with the message "System already registered.".

The error which appears when running my task with version b3b598c and later:

```
    TASK [satellite-client : register rhn] ***************************************************************************************************************************************************************************
    task path: /home/ansible/satellite-client/tasks/main.yml:15
    Using module file /usr/lib/python2.7/site-packages/ansible/modules/packaging/os/rhn_register.py
    <10.123.123.123> ESTABLISH SSH CONNECTION FOR USER: root
    <10.123.123.123> SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/c2d250d71c 10.123.123.123 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
    <10.123.123.123> (0, '/root\n', 'OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: 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 = 32570\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')
    <10.123.123.123> ESTABLISH SSH CONNECTION FOR USER: root
    <10.123.123.123> SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/c2d250d71c 10.123.123.123 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734 `" && echo ansible-tmp-1495638489.06-58962211270734="` echo /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734 `" ) && sleep 0'"'"''
    <10.123.123.123> (0, 'ansible-tmp-1495638489.06-58962211270734=/root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734\n', 'OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: 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 = 32570\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')
    <10.123.123.123> PUT /tmp/tmpP4VL2c TO /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/rhn_register.py
    <10.123.123.123> SSH: EXEC sshpass -d12 sftp -o BatchMode=no -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/c2d250d71c '[10.123.123.123]'
    <10.123.123.123> (0, 'sftp> put /tmp/tmpP4VL2c /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/rhn_register.py\n', 'OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: 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 = 32570\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 . -> /root size 0\r\ndebug3: Looking up /tmp/tmpP4VL2c\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:/root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/rhn_register.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:31831\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 5 31831 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')
    <10.123.123.123> ESTABLISH SSH CONNECTION FOR USER: root
    <10.123.123.123> SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/c2d250d71c 10.123.123.123 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/ /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/rhn_register.py && sleep 0'"'"''
    <10.123.123.123> (0, '', 'OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: 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 = 32570\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')
    <10.123.123.123> ESTABLISH SSH CONNECTION FOR USER: root
    <10.123.123.123> SSH: EXEC sshpass -d12 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/c2d250d71c -tt 10.123.123.123 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/rhn_register.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1495638489.06-58962211270734/" > /dev/null 2>&1 && sleep 0'"'"''
    <10.123.123.123> (0, '\r\n{"msg": "Failed to register with \'satserver.domain.com\': cannot marshal None unless allow_none is enabled", "failed": true, "invocation": {"module_args": {"username": null, "systemorgid": null, "enable_eus": false, "server_url": "https://satserver.domain.com/XMLRPC", "channels": [], "state": "present", "sslcacert": null, "activationkey": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "profilename": "testserver1", "password": null}}}\r\n', 'OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: 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 = 32570\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 10.123.123.123 closed.\r\n')
    fatal: [10.123.123.123]: FAILED! => {
        "changed": false,
        "failed": true,
        "invocation": {
            "module_args": {
                "activationkey": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "channels": [],
                "enable_eus": false,
                "password": null,
                "profilename": "testserver1",
                "server_url": "https://satserver.domain.com/XMLRPC",
                "sslcacert": null,
                "state": "present",
                "systemorgid": null,
                "username": null
            }
        },
        "msg": "Failed to register with 'satserver.domain.com': cannot marshal None unless allow_none is enabled"
    }
```

##### FURTHER DETAILS

This issue was also reported in https://github.com/ansible/ansible/issues/22300#issuecomment-290036871 but it does not appear to be fixed by any of the changes mentioned in https://github.com/ansible/ansible/issues/22300 or the changes in https://github.com/ansible/ansible/commit/fb6e9e8fbe6c34f10611c92b4d0c481eca44c06d . Because of these details, I believe this to be a distinct issue.

I believe the changes at 7faef2c caused this problem. I have tested numerous versions of rhn_register.py in Ansible 2.3.0.0 to come to this conclusion.

I have created a version of rhn_register.py that resolves the error in Ansible 2.3.0.0: https://gist.github.com/WhyIsThisOpen/d48b9a01b7d658b6ec23fd29ae801ad2


Discussion:
cc @barnabycourt @vritant @flossware @alikins
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@WhyIsThisOpen would you mind submitting that patch as a pullrequest?

needs_info
Done. I tried to follow the pattern of other pull requests; hopefully that is correct.
cc @barnabycourt @vritant @flossware @alikins
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@WhyIsThisOpen would you mind submitting that patch as a pullrequest?

needs_info
Done. I tried to follow the pattern of other pull requests; hopefully that is correct.

Resolving patch:
diff --git a/lib/ansible/modules/packaging/os/rhn_register.py b/lib/ansible/modules/packaging/os/rhn_register.py
--- a/lib/ansible/modules/packaging/os/rhn_register.py
+++ b/lib/ansible/modules/packaging/os/rhn_register.py
@@ -81,6 +81,12 @@
             - If true, extended update support will be requested.
         required: false
         default: false
+    nopackages:
+        description:
+            - If true, the registered node will not upload its installed packages information to Satellite server
+        required: false
+        default: false
+        version_added: "2.5"
 '''
 
 EXAMPLES = '''
@@ -250,7 +256,7 @@ def enable(self):
         self.update_plugin_conf('rhnplugin', True)
         self.update_plugin_conf('subscription-manager', False)
 
-    def register(self, enable_eus=False, activationkey=None, profilename=None, sslcacert=None, systemorgid=None):
+    def register(self, enable_eus=False, activationkey=None, profilename=None, sslcacert=None, systemorgid=None, nopackages=False):
         '''
             Register system to RHN.  If enable_eus=True, extended update
             support will be requested.
@@ -262,6 +268,8 @@ def register(self, enable_eus=False, activationkey=None, profilename=None, sslca
             register_cmd.extend(['--serverUrl', self.server_url])
         if enable_eus:
             register_cmd.append('--use-eus-channel')
+        if nopackages:
+            register_cmd.append('--nopackages')
         if activationkey is not None:
             register_cmd.extend(['--activationkey', activationkey])
         if profilename is not None:
@@ -346,6 +354,7 @@ def main():
             sslcacert=dict(default=None, required=False, type='path'),
             systemorgid=dict(default=None, required=False),
             enable_eus=dict(default=False, type='bool'),
+            nopackages=dict(default=False, type='bool'),
             channels=dict(default=[], type='list'),
         )
     )
@@ -364,6 +373,7 @@ def main():
     systemorgid = module.params['systemorgid']
     channels = module.params['channels']
     enable_eus = module.params['enable_eus']
+    nopackages = module.params['nopackages']
 
     rhn = Rhn(module=module, username=username, password=password)
 
@@ -392,7 +402,7 @@ def main():
 
         try:
             rhn.enable()
-            rhn.register(enable_eus, activationkey, profilename, sslcacert, systemorgid)
+            rhn.register(enable_eus, activationkey, profilename, sslcacert, systemorgid, nopackages)
             rhn.subscribe(channels)
         except Exception as exc:
             module.fail_json(msg="Failed to register with '%s': %s" % (rhn.hostname, exc))


Test patch: