community.general/lib/ansible/module_utils
Toshio Kuratomi 52449cc01a AnsiballZ improvements
Now that we don't need to worry about python-2.4 and 2.5, we can make
some improvements to the way AnsiballZ handles modules.

* Change AnsiballZ wrapper to use import to invoke the module
  We need the module to think of itself as a script because it could be
  coded as:

      main()

  or as:

      if __name__ == '__main__':
          main()

  Or even as:

      if __name__ == '__main__':
          random_function_name()

  A script will invoke all of those.  Prior to this change, we invoked
  a second Python interpreter on the module so that it really was
  a script.  However, this means that we have to run python twice (once
  for the AnsiballZ wrapper and once for the module).  This change makes
  the module think that it is a script (because __name__ in the module ==
  '__main__') but it's actually being invoked by us importing the module
  code.

  There's three ways we've come up to do this.
  * The most elegant is to use zipimporter and tell the import mechanism
    that the module being loaded is __main__:
    * 5959f11c9d/lib/ansible/executor/module_common.py (L175)
    * zipimporter is nice because we do not have to extract the module from
      the zip file and save it to the disk when we do that.  The import
      machinery does it all for us.
    * The drawback is that modules do not have a __file__ which points
      to a real file when they do this.  Modules could be using __file__
      to for a variety of reasons, most of those probably have
      replacements (the most common one is to find a writable directory
      for temporary files.  AnsibleModule.tmpdir should be used instead)
      We can monkeypatch __file__ in fom AnsibleModule initialization
      but that's kind of gross.  There's no way I can see to do this
      from the wrapper.

  * Next, there's imp.load_module():
    * 340edf7489/lib/ansible/executor/module_common.py (L151)
    * imp has the nice property of allowing us to set __name__ to
      __main__ without changing the name of the file itself
    * We also don't have to do anything special to set __file__ for
      backwards compatibility (although the reason for that is the
      drawback):
    * Its drawback is that it requires the file to exist on disk so we
      have to explicitly extract it from the zipfile and save it to
      a temporary file

  * The last choice is to use exec to execute the module:
    * f47a4ccc76/lib/ansible/executor/module_common.py (L175)
    * The code we would have to maintain for this looks pretty clean.
      In the wrapper we create a ModuleType, set __file__ on it, read
      the module's contents in from the zip file and then exec it.
    * Drawbacks: We still have to explicitly extract the file's contents
      from the zip archive instead of letting python's import mechanism
      handle it.
    * Exec also has hidden performance issues and breaks certain
      assumptions that modules could be making about their own code:
      http://lucumr.pocoo.org/2011/2/1/exec-in-python/

  Our plan is to use imp.load_module() for now, deprecate the use of
  __file__ in modules, and switch to zipimport once the deprecation
  period for __file__ is over (without monkeypatching a fake __file__ in
  via AnsibleModule).

* Rename the name of the AnsiBallZ wrapped module
  This makes it obvious that the wrapped module isn't the module file that
  we distribute.  It's part of trying to mitigate the fact that the module
  is now named __main)).py in tracebacks.

* Shield all wrapper symbols inside of a function
  With the new import code, all symbols in the wrapper become visible in
  the module.  To mitigate the chance of collisions, move most symbols
  into a toplevel function.  The only symbols left in the global namespace
  are now _ANSIBALLZ_WRAPPER and _ansiballz_main.

revised porting guide entry

Integrate code coverage collection into AnsiballZ.

ci_coverage
ci_complete
2018-07-26 20:07:25 -07:00
..
aws [aws] Add missing methods to AnsibleAWSModule (#42679) 2018-07-12 09:47:28 -04:00
common Provide kubernetes definition diffs in check_mode (#41471) 2018-07-11 16:32:03 +10:00
compat Adds the ipaddress compat library backport from Python 3.x (#42265) 2018-07-17 11:37:23 -07:00
facts fix fedora version dnf fact, default pkg_mgr detection per distro family (#43261) 2018-07-25 16:20:07 -07:00
k8s Add merge_type parameter to k8s module (#42219) 2018-07-22 21:05:25 -07:00
net_tools Add the NIOS RECORD PTR Module (#41900) 2018-07-11 23:55:28 +05:30
network Add support for commit label in iosxr_config (#42931) 2018-07-24 17:16:26 +05:30
parsing Improve convert_bool error message 2018-02-12 13:05:38 -05:00
powershell Make the code more PowerShell compliant (#39464) 2018-07-16 11:34:01 +10:00
remote_management Connection and MAC pool module for Cisco UCS (#31151) 2017-12-14 19:38:35 +01:00
six Update the bundled six library to 1.11.0 2017-09-17 22:00:02 -07:00
__init__.py Enhance empty __init__ code-smell to check module_utils (#33438) 2017-11-30 15:47:38 -08:00
_text.py Fix for to_text and to_bytes error handlers 2017-07-24 09:19:04 -07:00
acme.py ACME modules: documentation improvements (#42165) 2018-07-04 15:22:11 +02:00
ansible_release.py [AWS] Add Ansible Version to botocore user agent string (#39993) 2018-05-17 11:41:14 -04:00
ansible_tower.py Fix tower_* modules **params kwargs (#40137) 2018-05-25 18:03:12 -05:00
api.py Remove comments about import order 2017-08-07 19:46:06 -07:00
azure_rm_common.py fixed passing non-default base_url from explicitly set cloud_environment (#40225) 2018-06-07 14:53:05 +08:00
azure_rm_common_rest.py introducing azure_rm_resource (#39274) 2018-05-23 16:55:57 -07:00
basic.py AnsiballZ improvements 2018-07-26 20:07:25 -07:00
cloud.py AWSRetry: allow retrying on additional ClientError exceptions (#28483) 2017-08-22 15:31:20 -04:00
cloudscale.py cloudscale_floating_ip module (#33181) 2017-12-11 14:48:35 +00:00
cloudstack.py cloudstack: fix query tags by resourceid (#40482) 2018-05-21 17:16:44 +02:00
connection.py Let called functions use method keyword (#43086) 2018-07-22 15:26:44 -04:00
crypto.py Allow multiple values per key in name fields in openssl_certificate/csr (#30338) 2017-12-12 12:35:22 +00:00
database.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
digital_ocean.py Include Digital Ocean Token Alias (#36810) 2018-03-01 09:56:53 +05:30
dimensiondata.py dimensiondata: fix broken import (#35634) 2018-02-07 00:44:42 +01:00
docker_common.py Fix ssl_version default value. (#42955) 2018-07-20 11:32:04 -04:00
ec2.py [AWS] Add Ansible Version to botocore user agent string (#39993) 2018-05-17 11:41:14 -04:00
exoscale.py exo_dns_record: remove limitation for multiple records only for A type (#35173) 2018-02-05 22:40:02 +01:00
f5_utils.py Refactor common network shared and platform utils code into package (#33452) 2017-12-03 21:42:30 +05:30
firewalld.py refactor firewalld module, add firewalld module_util (#37603) 2018-04-30 15:33:28 -05:00
gcdns.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
gce.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
gcp.py Fix dangerous default args. (#29839) 2017-09-12 00:11:13 -07:00
gcp_utils.py GCP Inventory Plugin scopes fix 2018-06-08 13:04:37 -07:00
gitlab.py Fix shebangs and file modes and update tests. (#40563) 2018-05-22 14:25:36 -07:00
heroku.py New module: heroku_collaborator (#39001) 2018-05-22 11:50:53 +02:00
infinibox.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
influxdb.py influxdb: Add condition for retries argument (#38441) 2018-04-15 22:05:51 -04:00
ipa.py FreeIPA: new module ipa_config (#42279) 2018-07-17 06:57:54 -04:00
ismount.py fix typo 2016-02-08 19:10:04 +01:00
json_utils.py jsonify inventory (#32990) 2017-11-21 13:41:27 -08:00
keycloak.py New module: keycloak_clienttemplate (#33419) 2018-01-31 13:12:53 +00:00
known_hosts.py Fix invalid string escape sequences. 2017-11-21 10:03:34 -08:00
ldap.py LDAP: Refactor and add ldap_passwd module (#33040) 2018-04-27 15:54:05 +05:30
lxd.py Use to_text helper function to handle bytes and unicode 2017-06-05 11:58:19 -07:00
manageiq.py Fix shebangs and file modes and update tests. (#40563) 2018-05-22 14:25:36 -07:00
memset.py New Memset module to request DNS reloads (#40390) 2018-05-25 00:30:25 +02:00
mysql.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
netapp.py Add Na_ontap_broadcast_domain module. (#39753) 2018-05-18 17:17:01 -07:00
oneandone.py New module: manage 1&1 public ip (cloud/oneandone/oneandone_public_ip) (#35079) 2018-02-07 12:15:27 -06:00
oneview.py DatacenterFactsModule for HPE OneView (#32701) 2017-11-28 13:49:51 +00:00
opennebula.py Fix opennebula test stub (#40436) 2018-05-25 07:42:14 +02:00
openstack.py openstack: Correct fail_json call in module_utils (#41064) 2018-06-04 10:18:15 +02:00
ovirt.py Fix PEP 8 issue. 2018-05-23 09:29:37 -07:00
postgres.py Remove wildcard imports and get_exception calls 2017-08-12 00:48:53 -07:00
pure.py Initial commit for Pure Storage FlashBlade module (#32467) 2018-02-22 15:33:48 -05:00
pycompat24.py Fix undefined variables, basestring usage, and some associated python3 issues 2017-07-25 15:58:23 -07:00
rax.py Fix invalid string escape sequences. 2017-11-21 10:03:34 -08:00
redhat.py Miscellaneous pylint fixes. 2017-09-13 01:53:08 -07:00
scaleway.py Add a User-Agent string to the API request (#38587) 2018-05-14 09:55:47 -05:00
service.py sysvinit service module (#34962) 2018-05-17 17:32:27 -05:00
splitter.py Collated PEP8 fixes (#25293) 2017-06-02 12:14:11 +01:00
univention_umc.py Python 2.6 str.format() compatibility fixes. 2018-01-10 14:08:11 -08:00
urls.py Only assume GET if no data, otherwise POST (#43133) 2018-07-23 07:30:10 -07:00
vca.py Use response.content instead of response object (#25772) 2017-08-14 12:40:06 -04:00
vmware.py vmware_vmotion: added storage vmotion capabilities. (#21421) 2018-07-17 20:43:30 +05:30
vmware_rest_client.py VMware: New module: vmware_tag (#37261) 2018-05-07 16:30:16 +05:30
vultr.py Vultr: Introducing vr_sshkey_facts module (#42615) 2018-07-18 09:53:58 +02:00