

##### SUMMARY
apt_repository throws exception "TypeError: instancemethod expected at least 2 arguments, got 0"
This is the same issue than #57195 which has been closed, but still persist. 

Please note that I'm fully aware that python 2.6 is old, and debian6 is very old. 
However the documentation says that python2.6 is supported for managed nodes (and not for management Host), so this module is expected to work on this system, and actually it WAS working before ansible 2.9 release. 
Thanks. 


##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
apt_repository

##### ANSIBLE VERSION

```
ansible 2.9.7
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/some/path/to/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Nov  7 2019, 10:07:09) [GCC 9.2.1 20191008]

```

##### CONFIGURATION

```paste below
DEFAULT_ROLES_PATH(/etc/ansible/ansible.cfg) = [u'/some/path/to/ansible/ansible-playbooks/roles']

```

##### OS / ENVIRONMENT

Ansible managed host: Debian 6 (squeeze)
Ansible management Host : Ubuntu 19.10 (eoan)


##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
    - name: Debian Install Debian Archive repository if unsupported release
      apt_repository: repo='deb http://archive.debian.org/debian {{ ansible_lsb.codename }} main contrib non-free' state=present

```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
```paste below
changed: [test-wheezy] => {
    "changed": true, 
    "diff": {}, 
    "invocation": {
        "module_args": {
            "codename": null, 
            "filename": null, 
            "install_python_apt": true, 
            "mode": null, 
            "repo": "deb http://archive.debian.org/debian wheezy main contrib non-free", 
            "state": "present", 
            "update_cache": true, 
            "validate_certs": true
        }
    }, 
    "repo": "deb http://archive.debian.org/debian wheezy main contrib non-free", 
    "state": "present"
}
```

##### ACTUAL RESULTS

```paste below
The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1588602884.56-23679-48530295011405/AnsiballZ_apt_repository.py", line 102, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1588602884.56-23679-48530295011405/AnsiballZ_apt_repository.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1588602884.56-23679-48530295011405/AnsiballZ_apt_repository.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible.modules.packaging.os.apt_repository', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python2.6/runpy.py", line 136, in run_module
    fname, loader, pkg_name)
  File "/usr/lib/python2.6/runpy.py", line 54, in _run_module_code
    mod_loader, pkg_name)
  File "/usr/lib/python2.6/runpy.py", line 34, in _run_code
    exec code in run_globals
  File "/tmp/ansible_apt_repository_payload_WYbsqp/ansible_apt_repository_payload.zip/ansible/modules/packaging/os/apt_repository.py", line 564, in <module>
  File "/tmp/ansible_apt_repository_payload_WYbsqp/ansible_apt_repository_payload.zip/ansible/modules/packaging/os/apt_repository.py", line 519, in main
  File "/usr/lib/python2.6/copy.py", line 189, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python2.6/copy.py", line 338, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python2.6/copy.py", line 162, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.6/copy.py", line 255, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python2.6/copy.py", line 189, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python2.6/copy.py", line 338, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python2.6/copy.py", line 162, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.6/copy.py", line 255, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python2.6/copy.py", line 162, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python2.6/copy.py", line 255, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python2.6/copy.py", line 189, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python2.6/copy.py", line 323, in _reconstruct
    y = callable(*args)
  File "/usr/lib/python2.6/copy_reg.py", line 93, in __newobj__
    return cls.__new__(cls, *args)
TypeError: instancemethod expected at least 2 arguments, got 0
fatal: [heb-3ce-164-3ce-164]: FAILED! => {
    "changed": false, 
    "module_stderr": "Shared connection to 194.2.77.164 closed.\r\n", 
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1588602884.56-23679-48530295011405/AnsiballZ_apt_repository.py\", line 102, in <module>\r\n    _ansiballz_main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1588602884.56-23679-48530295011405/AnsiballZ_apt_repository.py\", line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/root/.ansible/tmp/ansible-tmp-1588602884.56-23679-48530295011405/AnsiballZ_apt_repository.py\", line 40, in invoke_module\r\n    runpy.run_module(mod_name='ansible.modules.packaging.os.apt_repository', init_globals=None, run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib/python2.6/runpy.py\", line 136, in run_module\r\n    fname, loader, pkg_name)\r\n  File \"/usr/lib/python2.6/runpy.py\", line 54, in _run_module_code\r\n    mod_loader, pkg_name)\r\n  File \"/usr/lib/python2.6/runpy.py\", line 34, in _run_code\r\n    exec code in run_globals\r\n  File \"/tmp/ansible_apt_repository_payload_WYbsqp/ansible_apt_repository_payload.zip/ansible/modules/packaging/os/apt_repository.py\", line 564, in <module>\r\n  File \"/tmp/ansible_apt_repository_payload_WYbsqp/ansible_apt_repository_payload.zip/ansible/modules/packaging/os/apt_repository.py\", line 519, in main\r\n  File \"/usr/lib/python2.6/copy.py\", line 189, in deepcopy\r\n    y = _reconstruct(x, rv, 1, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 338, in _reconstruct\r\n    state = deepcopy(state, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 162, in deepcopy\r\n    y = copier(x, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 255, in _deepcopy_dict\r\n    y[deepcopy(key, memo)] = deepcopy(value, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 189, in deepcopy\r\n    y = _reconstruct(x, rv, 1, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 338, in _reconstruct\r\n    state = deepcopy(state, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 162, in deepcopy\r\n    y = copier(x, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 255, in _deepcopy_dict\r\n    y[deepcopy(key, memo)] = deepcopy(value, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 162, in deepcopy\r\n    y = copier(x, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 255, in _deepcopy_dict\r\n    y[deepcopy(key, memo)] = deepcopy(value, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 189, in deepcopy\r\n    y = _reconstruct(x, rv, 1, memo)\r\n  File \"/usr/lib/python2.6/copy.py\", line 323, in _reconstruct\r\n    y = callable(*args)\r\n  File \"/usr/lib/python2.6/copy_reg.py\", line 93, in __newobj__\r\n    return cls.__new__(cls, *args)\r\nTypeError: instancemethod expected at least 2 arguments, got 0\r\n", 
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 
    "rc": 1
}

```

if params['install_python_apt']:
            install_python_apt(module)
        else:
            module.fail_json(msg='%s is not installed, and install_python_apt is False' % PYTHON_APT)
    if not repo:
        module.fail_json(msg='Please set argument \'repo\' to a non-empty value')
    if isinstance(distro, aptsources_distro.Distribution):
        sourceslist = UbuntuSourcesList(module, add_ppa_signing_keys_callback=get_add_ppa_signing_key_callback(module))
    else:
        module.fail_json(msg='Module apt_repository is not supported on target.')
    sourceslist_before = copy.deepcopy(sourceslist)
    sources_before = sourceslist.dump()
    try:
        if state == 'present':
            sourceslist.add_source(repo)
        elif state == 'absent':
            sourceslist.remove_source(repo)
    except InvalidSource as err:
        module.fail_json(msg='Invalid repository string: %s' % to_native(err))
    sources_after = sourceslist.dump()
    changed = sources_before != sources_after
    if changed and module._diff:
        diff = []
        for filename in set(sources_before.keys()).union(sources_after.keys()):
            diff.append({'before': sources_before.get(filename, ''),
                         'after': sources_after.get(filename, ''),
                         'before_header': (filename, '/dev/null')[filename not in sources_before],
                         'after_header': (filename, '/dev/null')[filename not in sources_after]})
    else:
        diff = {}