Commit graph

388 commits

Author SHA1 Message Date
Tyler Gregory
6dfc82fe3e Set win_rm protocol to the name, not the full ProtocolTypes object (#37499) 2018-03-21 15:37:48 +10:00
Peter Schiffer
8c992ccbc7 Allow filtering of instances by tags in GCE dynamic inventory (#35770)
* Allow filtering of instances by tags in GCE dynamic inventory

* Optimize instance tags configuration

* Fix for PEP8
2018-03-14 14:09:06 -04:00
Pilou
1c43f7c482 FreeIPA inventory (ipalib 4.6.2): avoid exception (#34356)
Workaround for https://pagure.io/freeipa/issue/7345.

mentions:
- IPA_CONFDIR environment variable when directory doesn't exist
- domain, xmlrpc_uri or jsonrpc_uri parameters when one is missing

Exception was:
$ IPA_CONFDIR=/path/to/empty/dir ./ansible/contrib/inventory/freeipa.py --list
Traceback (most recent call last):
  File "./ansible/contrib/inventory/freeipa.py", line 95, in <module>
    api = initialize()
  File "./ansible/contrib/inventory/freeipa.py", line 18, in initialize
    api.finalize()
  File "local/lib/python2.7/site-packages/ipalib/plugable.py", line 738, in finalize
    self.__do_if_not_done('load_plugins')
  File "local/lib/python2.7/site-packages/ipalib/plugable.py", line 425, in __do_if_not_done
    getattr(self, name)()
  File "local/lib/python2.7/site-packages/ipalib/plugable.py", line 618, in load_plugins
    for package in self.packages:
  File "local/lib/python2.7/site-packages/ipalib/__init__.py", line 949, in packages
    ipaclient.remote_plugins.get_package(self),
  File "local/lib/python2.7/site-packages/ipaclient/remote_plugins/__init__.py", line 120, in get_package
    server_info = ServerInfo(api)
  File "local/lib/python2.7/site-packages/ipaclient/remote_plugins/__init__.py", line 26, in __init__
    hostname = DNSName(api.env.server).ToASCII()
AttributeError: 'Env' object has no attribute 'server'
2018-02-26 05:07:51 -05:00
Monty Taylor
0f893027c4 Add a module_utils OpenStack Cloud constructor (#20974)
Start using this to construct shade OpenStack Cloud objects in a
consistent manner. This will let us centralize things like dealing with
password arguments and whatnot. It also allows us to introduce the
ability to pass a fully formed config dict directly to the module.

Migrate all OpenStack modules to use openstack_cloud_from_module.

Have it return the shade library since it's responsible for
importing shade and shade is needed for the exceptions.

Only pull specific OpenStack arguments for the constructor

Rather than passing **module.params to the shade constructor, pull out
only the values that make sense. This should prevent the issues with
module parameters stepping on shade parameters.

Replace module.params.pop with module.params.get

We don't need to pop these anymore since the shade constructor is now
using opt-in values.

Using real urls is ungood. Use example.com domains. Also, get rid of the
antiquated port numbers.
2018-02-15 15:20:49 +01:00
ABond
2940b9d5bb Removed sort from json dump since response is a mix of strings and integers (#34217) 2018-02-10 07:52:10 +05:30
Simon Wydooghe
c119f6e642 Add 'digital_ocean' as group (#21631) 2018-02-10 07:48:03 +05:30
Paul B
ccdc93ab59 contrib(inventory): fix Scaleway inventory used w/env variable token (#35701)
In order to authenticate with the Scaleway API for the contrib dynamic
inventory Scaleway the environment variable SCALEWAY_TOKEN was read
only if a value was set in the configuration .ini file.

This PR fixes that allowing to read only the environment variable
without needing to set a token in the configuration file.

Closes #35693
2018-02-05 08:32:49 +00:00
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.
2018-02-01 10:33:51 -05:00
Clement Trebuchet
862c439223 Contrib infoblox exattrs Fixes #35409 (#35410)
* *FIX: re-create the exattrs dict into the hostvars[name] dict

* *FIX: remove unwanted files

* Fixes #35409: put an str instead of variable
2018-01-31 09:17:34 -05:00
Peter Sprygada
c2d3b9cbd5
refactors nios api shared code to handle provider better (#35393)
* refactors nios api shared code to handle provider better

This change refactors the shared code to be easily shared between
modules, plugins and dynamic inventory scripts.  All parts now implement
the provider arguments uniformly.

This also provides a centralized fix to suppress urllib3 warnings coming
from the requests library implemented by infoblox_client

* fix up pep8 errors

* fix missing var name
2018-01-27 08:03:06 -05:00
Peter Sprygada
3f556f2e37
adds infoblox dynamic inventory script (#35328)
* adds infoblox dynamic inventory script

* fix up issues from sanity testing

* fix pep8 issues
2018-01-25 14:29:11 -05:00
Jonathan McCall
cdf8f29e70 Add hash making inventory caches unique to inventory script ran (#34742) 2018-01-23 13:10:22 -05:00
Sam Edwards
a1639abd71 Fix Digital Ocean inventory script pagination handling (#35153) 2018-01-23 19:29:50 +05:30
Kristóf Havasi
1c22d82c5e consul_io: fixed service availability check (#34293)
service is only up if the node publishing it is also available
2018-01-19 16:33:52 -05:00
Fabrice Flore-Thébault
5b52bfad6d azure_rm inventory should add "ansible_connection: winrm" in host_vars for windows hosts - fixes #34689 (#34691)
* fix for https://github.com/ansible/ansible/issues/34689
azure_rm inventory should add "ansible_connection: winrm" in host_vars for windows hosts

* add ansible_connection: winrm - fix for https://github.com/ansible/ansible/issues/34689
2018-01-18 05:49:50 +10:00
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
2018-01-17 06:36:17 -08:00
Abhijeet Kasurde
191b934dbd
freeipa: support for host vars (#34535)
Adds method to return host vars related to FreeIPA hostname.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2018-01-15 13:57:30 +05:30
Danilo Riecken P. de Morais
5540e2f8a9 cloudstack: inventory: Added feature list by tag (#31319) 2018-01-14 20:42:31 +01:00
Paul B
9302e8d2a4 contrib(inventory): adds a dynamic inventory for Scaleway cloud (#30313)
provider

Provides a dynamic inventory plugin for Scaleway cloud provider with
the following features:

- Configurable scaleway.ini file
- Cache API responses
- Choose public or private IPs
- Create groups per Scaleway 'tags'
- Create groups per Scaleway regions
2018-01-13 14:55:05 +00:00
Matt Clay
797664d9cb Python 2.6 str.format() compatibility fixes. 2018-01-10 14:08:11 -08:00
Fedele Mantuano
70fd5d4caf More stable explicit file close. (#34303) 2018-01-02 10:03:44 -06:00
Abhijeet Kasurde
0eb2644c1c Fix redeclaration of get_host_info function (#33608)
This fix redeclaration of get_host_info method in linode
inventory.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2018-01-02 10:24:53 -05:00
Kristóf Havasi
a05ed65295 consul_io.py: typo fixed in docs (#34292) 2017-12-30 03:08:28 +01:00
Kristóf Havasi
6ba6c7e67c contrib/inventory/consul_io: typo fixed in documentation (#34291) 2017-12-29 16:49:37 +05:30
Robert "Bo" Davis
b5c0141fb0 Use hostname in group_by_aws_account to prevent duplicates. (#34053)
Fix typo. The use of `dest` for group_by_aws_account causes the group to be produced using IP and to duplicate the hosts in the inventory.

Fixes #23772

Signed-off-by: bo <robert@jbanetwork.com>
2017-12-19 17:04:46 -05:00
Ryan Groten
b34d150bec Use hostgroup_find(all=True) returns member hosts of all hostgroups in a single call (#29106) 2017-12-18 12:28:19 -05:00
Abhijeet Kasurde
36f82ae8cc Replace exit() with sys.exit()
This fix adds replacement for exit() to sys.exit(), as
exit() is not recommended way to exit from the program.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2017-12-14 22:03:08 -05:00
Giovanni Sciortino
ff923fb6b0 Add scan_new_hosts feature in ansible foreman inventory (#33743) 2017-12-14 15:10:42 -05:00
pymag09
92c5b758f8 Improve consul_io.py execution speed (#33737)
* Improve execution speed

* fix missing whitespace
2017-12-13 13:33:28 +00:00
Abhijeet Kasurde
ebd6db7a1c
Digital Ocean Inventory refactor (#29176)
* Remove 'dopy' dependency
* Update documentation
* Incorporate BondAnthony's IP address related code
* Incorporate andrewsomething's Pagination code
* Add Tags support

Fixes: #15752

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2017-12-09 11:27:18 +05:30
Ryan MacLean
d7ca068c3f [cloud] Typo fixes for ec2 dynamic inventory (#32957) 2017-11-30 09:58:30 -05:00
Abhijeet Kasurde
449a0f33e1
Fix ConfigParser.set error in vmware_inventory (#31643)
Fix adds default 'vmware' section in configuration,
when this section is not found.

Fixes: #31549

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2017-11-28 22:52:59 +05:30
Matt Clay
e45c763b64 Fix invalid string escape sequences. 2017-11-21 10:03:34 -08:00
Abhijeet Kasurde
d372cea2f8
VMware: change default host_filter to gueststate (#32839)
This fix changes default value of host_filter in vmware_inventory.py
and vmware_inventory.ini to 'runtime.powerstate' from 'guest.gueststate'.
This change is added as 'guest.gueststate' requires vmware tools to be
installed on given VM, which may not be the case everytime.

Fixes: #25086

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2017-11-21 04:32:18 +00:00
gamuniz
10866bfb8b Exception handling in vmware_inventory for vcsim (#32700)
* vmware_inventory changes to support vcsim
* updated debug message per maintainer request
2017-11-12 21:29:25 -05:00
Kenny Woodson
c4af03118b Add support for tags and instance attributes for destination variable for the ec2 dynamic inventory. (#29033) 2017-10-24 16:09:59 -04:00
Ondra Machacek
a7df2322e4 ovirt: Add env variables to dynamic inventory (#31821)
This patch add new environment variables to oVirt dynamic inventory
to be consistent with all other oVirt modules:

 OVIRT_URL
 OVIRT_USERNAME
 OVIRT_CAFILE
 OVIRT_PASSWORD

Those variables are used as fallback if user don't specify a ini file,
with appropriate variables there.
2017-10-18 11:26:03 +01:00
Adrian Likins
297dfb1d50 Vault secrets script client inc new 'keyring' client (#27669)
This adds a new type of vault-password script  (a 'client') that takes advantage of and enhances the 
multiple vault password support.

If a vault password script basename ends with the name '-client', consider it a vault password script client. 

A vault password script 'client' just means that the script will take a '--vault-id' command line arg.

The previous vault password script (as invoked by --vault-password-file pointing to an executable) takes
no args and returns the password on stdout. But it doesnt know anything about --vault-id or multiple vault
passwords.

The new 'protocol' of the vault password script takes a cli arg ('--vault-id') so that it can lookup that specific
vault-id and return it's password.

Since existing vault password scripts don't know the new 'protocol', a way to distinguish password scripts
that do understand the protocol was needed.  The convention now is to consider password scripts that are
named like 'something-client.py' (and executable) to be vault password client scripts.

The new client scripts get invoked with the '--vault-id' they were requested for. An example:

     ansible-playbook --vault-id my_vault_id@contrib/vault/vault-keyring-client.py some_playbook.yml

That will cause the 'contrib/vault/vault-keyring-client.py' script to be invoked as:

     contrib/vault/vault-keyring-client.py --vault-id my_vault_id

The previous vault-keyring.py password script was extended to become vault-keyring-client.py. It uses
the python 'keyring' module to request secrets from various backends. The plain 'vault-keyring.py' script
would determine which key id and keyring name to use based on values that had to be set in ansible.cfg.
So it was also limited to one keyring name.

The new vault-keyring-client.py will request the secret for the vault id provided via the '--vault-id' option.
The script can be used without config and can be used for multiple keyring ids (and keyrings).

On success, a vault password client script will print the password to stdout and exit with a return code of 0.
If the 'client' script can't find a secret for the --vault-id, the script will exit with return code of 2 and print an error to stderr.
2017-10-13 15:23:08 -04:00
Matt Martz
e2f16cfaf7 Port vault-keyring.py to properly load the config. Fixes #31304 (#31315) 2017-10-13 13:46:24 -04:00
François Scala
aade5234a9 Fix urlparse import for Python3 (#31240)
* Fix urlparse import for Python3 in

* contrib/inventory/consul_io.py
* contrib/inventory/rudder.py
* contrib/inventory/windows_azure.py
* lib/ansible/module_utils/known_hosts.py
* lib/ansible/modules/cloud/centurylink/clc_firewall_policy.py
* lib/ansible/modules/cloud/docker/_docker.py
* lib/ansible/modules/cloud/ovirt/ovirt_disk.py
* lib/ansible/plugins/action/ce_template.py
2017-10-09 20:18:09 -07:00
Thomas Stringer
cb01f33d1e refactor azure dynamic inventory script configparser import to support python3 (#31370)
* refactor configparser import to support python3

* change ModuleNotFoundError to ImportError
2017-10-05 11:49:35 -07:00
Avner Cohen
d313c2d5e9 [cloud] RDS config should be getboolean, as per ec2.ini instructions (#31168) 2017-10-02 15:08:31 -04:00
Jiri Tyr
d35ef1fc21 [cloud][contrib] Set missing default values for EC2 inventory (#28375)
* Set missing default values for EC2 inventory

* Make it run even with no ec2.ini file

* Fixing INI file reading

* Refactor how defaults are handeled

Define defaults in a dictionary and use .get rather than if statements with has_option

* Removing double keys and fixing logic for instance_filter

* Removing one more doubled key
2017-09-29 10:48:48 -04:00
jctanner
219a6a67f1 Add a select_chain_match filter to vmware_inventory (#28778) 2017-09-27 19:06:01 -04:00
Martin Krizek
d804ac6f4b Implement AND'd filters in ec2.py/ini (#30272)
* Implement AND'd filters in ec2.py/ini

remove debug print

* Adjusting code to changed filters' data structure
2017-09-21 12:06:56 -04:00
Matt Clay
7714dcd04e Enable more pylint rules and fix reported issues. (#30539)
* Enable pylint unreachable test.
* Enable pylint suppressed-message test.
* Enable pylint redundant-unittest-assert test.
* Enable pylint bad-open-mode test.
* Enable pylint signature-differs test.
* Enable pylint unnecessary-pass test.
* Enable pylint unnecessary-lambda test.
* Enable pylint raising-bad-type test.
* Enable pylint logging-not-lazy test.
* Enable pylint logging-format-interpolation test.
* Enable pylint useless-else-on-loop test.
2017-09-18 23:20:32 -07:00
jchristi
9d5671db76 Allow filtering RDS instances by tags in the ec2 dynamic inventory script (#24423)
* Allow filtering RDS instances by tags in the ec2.py dynamic inventory script

* PEP8 fix

* Fix no-bastring code smell

* Simplify logic in ec2.py RDS filtering by tag
2017-09-14 10:58:16 -04:00
Matt Clay
442af3744e Miscellaneous pylint fixes.
The following rules are no longer disabled:

- bad-format-string
- duplicate-key
- lost-exception
- trailing-newlines
- unexpected-keyword-arg
- useless-suppression
- using-constant-test
2017-09-13 01:53:08 -07:00
Matt Clay
68aeaa58a8 Fix dangerous default args. (#29839) 2017-09-12 00:11:13 -07:00
Will Thames
f9a179f770 Handle missing docker-py better (#27540)
* Update docker inventory to use APIClient

docker-py has been updated, and the `Client` class no longer
exists. We use the new `APIClient` class.

To provide graceful failure when docker-py is not installed,
we need to create a dummy `Client` class so that the inventory
script will get as far as displaying a useful error message

Before

```
$ contrib/inventory/docker.py --pretty
Traceback (most recent call last):
  File "contrib/inventory/docker.py", line 418, in <module>
    class AnsibleDockerClient(Client):
NameError: name 'Client' is not defined
```

After

```
$ contrib/inventory/docker.py --pretty
Failed to import docker-py. Try `pip install docker-py` - cannot import name Client
```

* docker inventory configuration file location

Allow docker.yml to live next to docker.py, as well as in the
current directory
2017-09-10 19:06:57 -07:00