Commit Graph

6 Commits (b72960fdd4addbdbce2c7a28c4193e2d3f136cc8)

Author SHA1 Message Date
Richard Bywater 7dbcf752c8 Add ability to select to prefer IPv4 addresses for ansible_ssh_host (#35584)
Currently Cloudforms can return a mix of IPv4 and IPv6 addresses in the
ipaddresses field and this mix comes in a "random" order (that is the
first entry may be IPv4 sometimes but IPv6 other times). If you wish to
always use IPv4 for the ansible_ssh_host value then this is problematic.

This change adds a new prefer_ipv4 flag which will look for the first
IPv4 address in the ipaddresses list and uses that instead of just the
first entry.
7 years ago
Richard Bywater a7e27b74c9 Add ability to append suffix to host names for Cloudforms Inventory (#33565)
* Add ability to append suffix to host names for Cloudforms Inventory

Allows for use of a suffix that will be appended to host names returned
from Cloudforms API if that suffix is not present.

For example with a suffix of 'example.org', the following results
would be shown for a particular Cloudforms host name:
someexample -> someexample.example.org
someexample.example.org -> someexample.example.org

The main use-case for this is when Cloudforms has short names rather
than FQDN and there is a desire to to use the FQDN as the name.

* Add example line into Cloudforms INI file

* Clarify that leading fullstop needed

* Add validation to ensure leading fullstop for suffix
7 years ago
Matt Clay e45c763b64 Fix invalid string escape sequences. 7 years ago
Matt Clay 0d46805979 Clean up shebangs for various files.
- Remove shebangs from:
  - ini files
  - unit tests
  - module_utils
  - plugins
  - module_docs_fragments
  - non-executable Makefiles
- Change non-modules from '/usr/bin/python' to '/usr/bin/env python'.
- Change '/bin/env' to '/usr/bin/env'.

Also removed main functions from unit tests (since they no longer
have a shebang) and fixed a python 3 compatibility issue with
update_bundled.py so it does not need to specify a python 2 shebang.

A script was added to check for unexpected shebangs in files.
This script is run during CI on Shippable.
8 years ago
nitzmahone 4fbd17d949 py3 print fix 8 years ago
Josh Preston 2a2d866c0d add cloudforms inventory script (#17037)
* add cloudforms inventory script

based on the foreman inventory script, features:

* cached results (default 600 seconds)
* paginated host results (default 100 hosts)
* ssl verification (default True)
* arguments to flush cache and run in debug mode

* suggested rework

* removed second cache / dict with duplicate info
* added purge_actions configuration option to remove the actions from a host (defaults to False)
* added prefer_ip_address configuration option so give the option of using ip address instead of name (defaults to True)
* removed self variables — just use the arguments directly
* added --pretty command line option to pretty print results
* renamed _resolve_params to _resolve_host

* implement suggestions

* removed not used import
* added warnings to help debug connection issues
* renamed self.cache to self.hosts for clarity
* now will use the first ip address as ansible_ssh_host
* flipped default for prefer_ip_address config option to false - preserve name, and specify ansible_ssh_host as ip address
* added checks and warnings to configuration options, sane defaults for all except required:
** `url` - the first part of the cloudforms server url (https://cfme.example.com)
** `username`  - the cloudforms username to log in with
** `password` - the password for the cloudforms user specified
* removed redundant call to fetch host information (since we’re paging results, no need to split the calls)
* added warning for unexpected responses from CloudForms
* debug for returned sting now prints the string instead of forcing to JSON
* removed no longer needed methods to fetch host information
* using ‘key in list’ instead of ‘list.has_key(key)’
* correctly formatted groups and allowed nested groups
* now create groups for `location`, `type` and `vendor`, with appropriate sub-groups and children
* made to_safe honor config option to clean group names for ansible consumption

* remove prefer_ip_address configuration option

no longer needed since we will specify `ansible_ssh_host` as the returned ip address.

* removed dns_name

no longer needed, will preserve `host[name]` as name in Ansible.

* purge actions from hostvars

changed purge_actions to True

* flake8 suggestion for whitespace

* fix undefined r variable in warning output

use the correct ret variable

* Default purge_actions to True

We probably don’t need them, but it is configurable, so just default to remove them.

* Add configuration option to nest cloudforms tags

disabled by default, the nest_tags option will expand cloudforms tags into a nested group/subgroup structure.  Otherwise, it will use the whole tag name.

* added purging the actions

removed in previous clean up in error.

* fixed undefined variable

specified the correct variable for logging.
8 years ago