Commit Graph

413 Commits (cef4d862bc944fbcab082f2710575f2c14c7cd54)

Author SHA1 Message Date
Ryan Groten b34d150bec Use hostgroup_find(all=True) returns member hosts of all hostgroups in a single call (#29106) 7 years ago
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>
7 years ago
Giovanni Sciortino ff923fb6b0 Add scan_new_hosts feature in ansible foreman inventory (#33743) 7 years ago
pymag09 92c5b758f8 Improve consul_io.py execution speed (#33737)
* Improve execution speed

* fix missing whitespace
7 years ago
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>
7 years ago
Ryan MacLean d7ca068c3f [cloud] Typo fixes for ec2 dynamic inventory (#32957) 7 years ago
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>
7 years ago
Matt Clay e45c763b64 Fix invalid string escape sequences. 7 years ago
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>
7 years ago
gamuniz 10866bfb8b Exception handling in vmware_inventory for vcsim (#32700)
* vmware_inventory changes to support vcsim
* updated debug message per maintainer request
7 years ago
Kenny Woodson c4af03118b Add support for tags and instance attributes for destination variable for the ec2 dynamic inventory. (#29033) 7 years ago
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.
7 years ago
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.
7 years ago
Matt Martz e2f16cfaf7 Port vault-keyring.py to properly load the config. Fixes #31304 (#31315) 7 years ago
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
7 years ago
Thomas Stringer cb01f33d1e refactor azure dynamic inventory script configparser import to support python3 (#31370)
* refactor configparser import to support python3

* change ModuleNotFoundError to ImportError
7 years ago
Avner Cohen d313c2d5e9 [cloud] RDS config should be getboolean, as per ec2.ini instructions (#31168) 7 years ago
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
7 years ago
jctanner 219a6a67f1 Add a select_chain_match filter to vmware_inventory (#28778) 7 years ago
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
7 years ago
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.
7 years ago
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
7 years ago
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
7 years ago
Matt Clay 68aeaa58a8 Fix dangerous default args. (#29839) 7 years ago
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
7 years ago
Matt Davis 12700f61e7 fixed incorrect endpoint selection in azure_rm.py 7 years ago
Maciej Lasyk 5c0b94217e Added handling optional GCE_CREDENTIALS_FILE_PATH (#25526)
Ansible documentation states that env variable based authentication bases on variable GCE_CREDENTIALS_FILE_PATH while gce.py reads only GCE_PEM_FILE_PATH (see https://docs.ansible.com/ansible/guide_gce.html). This commit adds GCE_CREDENTIALS_FILE_PATH to the configuration chain; if set it will be used.
7 years ago
Matt Davis b3f2d1befe expose cloud_environment override in azure_rm modules (#28743)
* Can be set via env, credential profile, or module arg
* Valid values defined by Azure Python SDK, currently `AzureCloud`,`AzureChinaCloud`,`AzureUSGovernment`,`AzureGermanCloud` or any Azure Stack metadata discovery URL.
7 years ago
Alejandro Bednarik 9aa5e0cc3e Add GPL License header to freeipa inventory file. (#24353)
* Add GPl License header to freeipa incentory file.

* Short GPL license
7 years ago
furhouse af9396841e zabbix_inventory PEP8 compliance. (#28680) 7 years ago
jctanner 443b25d72a Fixup the property collection for dictionaries vs. objects (#28609)
* Fixup the property collection for dictionaries vs. objects

* Remove debug lines

* Do not attempt to sort because it's a waste

* Remove unused code

* Remove extra code

* Capture lowercase keys
7 years ago
jctanner 65feaa11b2 Fix valueerror in vmware_inventory.py (#28597) 7 years ago
David Kretch beed59f303 Fix trailing space in ec2_vol example, fix 'the the' typos (#28440)
* Fix 'the the' typos, fix 'pahting' filename typo

* Change 'the the' typos to a single 'the'.
* Change `playbook_pahting.rst` to `playbook_pathing.rst`.

* Delete trailing space in ec2_vol example

Delete the trailing space in `instance: "{{ item.id }} "`, which makes the
example fail when run because it looks for instance "i-xxxx ".
7 years ago
Abhijeet Kasurde c876f4f3cf Make FreeIPA inventory work (#25354)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
7 years ago
Andrea Tartaglia fd01a9bb99 Added GPL header to vmware_inventory.py (#24443) 7 years ago
Michael Overmeyer 930d5d88b7 Fix #24546 (#24562) 7 years ago
Sam Doran f35975f114 PEP8 fixes 7 years ago
Peter Hoffmann 6c9cb05cfd Use tenant in UserPassCredentials if set.
If you have multiple Tenants you need to set the tenant in https://github.com/Azure/msrestazure-for-python/blob/master/msrestazure/azure_active_directory.py otherwise the azure_rm.py call will fail.
7 years ago
Achraf Cherti e45d5b7e8e Compatibility of gce.py (Google Cloud Ansible inventory) with Python 3 (#26032)
* Compatibility of gce.py (inventory) with Python 3

* Revert './secrets.py' file check (will import 'secrets' from PYTHONPATH)

Instead of checking if secrets.py exists in the current directory, this
commit will make gce import 'secrets' from one of PYTHONPATH's paths.

There are 2 possibilities:
1. secrets.py will be used if secrets.GCE_PARAMS and
secrets.GCE_KEYWORD_PARAMS are declared.

2. secrets.py will be ignored if secrets.GCE_PARAMS and
secrets.GCE_KEYWORD_PARAMS aren't declared. This could happen in Python
>=3.6 where a module named 'secrets' could be imported if a custom
secrets.py doesn't exist in PYTHONPATH.
Check out https://www.python.org/dev/peps/pep-0506/ and
https://docs.python.org/3/library/secrets.html for more information.
7 years ago
James Portman 950e4b6505 Added checks for machine.os_profile is not None before trying to access child attributes (#22906) 7 years ago
Alvaro Aleman bb9c6694a7 Allow the Openstack dynamic inventory to discover ansible_user (#17944) 7 years ago
Gerard Lynch d9d983160d support OS_CLOUD in openstack dynamic inventory
allow a user to limit to a single cloud in clouds.yaml, and support
per-cloud caching.
7 years ago
Alvaro Aleman fe5e1a4bc4 OS dynamic inventory: respect OS_CLOUD env var 7 years ago
Do Hoang Khiem 3b12a85750 Add node private & public ips to gce groups (#12539) 7 years ago
Sebastian Cruz 223f94ec56 Fix missing option in #27848 (#27892) 7 years ago
Sebastian Cruz ce5e4dfc38 Add option to group ec2 instances by platform. (#27848)
All credits to https://github.com/felipecvo

See PR: https://github.com/ansible/ansible/pull/14246
7 years ago
Eric L 1fe14da226 Add possibility to interpret global parameters value as JSON with rich_params flag (#26180) 7 years ago
Adam Johnson 3f85aa3abd Use a real list comprehension rather than list() around a generator (#25594)
It's faster and more idiomatic.
7 years ago
Tian You 9364fa202f [cloud] Group RDS instances by tag keys in ec2 dynamic inventory (#24763) 7 years ago
jctanner 3b20585ada Fix 23417 (#27770)
* Expose user_metadat to ansible

* Fixed exception when no userData
7 years ago
Will Weber bfbdb3f3f0 assumption made that dopy only dep in dopy (#27536) 7 years ago
Nick Ball edf31f56af Linode inventory improvements: Add _meta/hostvars to inventory output. Add a 'linode' host group with all the hosts (#19329) 7 years ago
Toshio Kuratomi 225fa5d092 Fix undefined variables, basestring usage, and some associated python3 issues 7 years ago
Brian Coca 8f8e53acbe updated readme with vault and 2.4 inv plugins (#26361)
* updated readme with vault and 2.4 inv plugins

* fixed as per feedback

* Edits

Need clarification for lines 10 and 11.
7 years ago
Toshio Kuratomi edccfd5908 Fix undefined variable in libcloud dyn inv script
References #27193
7 years ago
Greg Dahlman 1d8854b045 Python 3 fix for consul_io inventory (#26510)
* Python 3 fix for consul_io inventory

* Remove configparser CamelCase try statement

* revert to python2.6 compatible try;except

* Fix pip8 error E302
7 years ago
Tomáš Karásek a5c41dcd49 Add grouping by hostname for the Packet inventory (#21069)
* Add grouping by hostname for the Packet inventory

* remove space after eol
7 years ago
Abhijeet Kasurde f7c8e7bdab Update vmware_inventory (#26308)
Fix adds
* Exception handling
* Unit tests

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
7 years ago
Josh Smift 290d84f904 Update ansible_ssh_host->ansible_host in ec2.py dynamic inventory (#17113) 7 years ago
Toshio Kuratomi ff22528b07 Consolidate boolean/mk_boolean conversion functions into a single location
Consolidate the module_utils, constants, and config functions that
convert values into booleans into a single function in module_utils.

Port code to use the module_utils.validate.convert_bool.boolean function
isntead of mk_boolean.
7 years ago
Alejandro Bednarik 2420bca0b5 Add GPl License header to rackhd inventory file. (#24354) 7 years ago
Ryan S. Brown 7cee903118 [cluster] Name Consul dynamic inventory config consistently w/ the script 7 years ago
Brian Coca 365f3dc9d9 switched to elif 7 years ago
Lorin Hochstein b17da1fae9 ec2.py: Better error messages for OptInRequired
Improve error messages for RDS and ElastiCache failures for code OptInRequired.
7 years ago
Matt Clay 2e85272cd5 PEP 8 fixes. 7 years ago
Ronny 955f8923e7 Update dynamic inventory zabbix.py (#19862)
Added _meta to improve the speed when using this dynamic inventory file
7 years ago
Toshio Kuratomi e238ae999b Cyptography pr 20566 rebase (#25560)
Make pyca/cryptography the preferred backend for cryptographic needs (mainly vault) falling back to pycrypto

pyca/cryptography is already implicitly a dependency in many cases
through paramiko (2.0+) as well as the new openssl_publickey module,
which requires pyOpenSSL 16.0+. Additionally, pyca/cryptography is
an optional dep for better performance with vault already.

This commit leverages cryptography's padding, constant time comparisons,
and CBC/CTR modes to reduce the amount of code ansible needs to
maintain.

* Handle wrong password given for VaultAES format

* Do not display deprecation warning for cryptography on python-2.6

* Namespace all of the pycrypto imports and always import them

  Makes unittests better and the code less likely to get stupid mistakes
  (like using HMAC from cryptogrpahy when the one from pycrypto is needed)

* Add back in atfork since we need pycrypto to reinitialize its RNG just in case we're being used with old paramiko

* contrib/inventory/gce: Remove spurious require on pycrypto

(cherry picked from commit 9e16b9db275263b3ea8d1b124966fdebfc9ab271)

* Add cryptography to ec2_win_password module requirements
  * Fix python3 bug which would pass text strings to a function which
    requires byte strings.

* Attempt to add pycrypto version to setup deps

* Change hacking README for dual pycrypto/cryptography

* update dependencies for various CI scripts

* additional CI dockerfile/script updates

* add paramiko to the windows and sanity requirement set

  This is needed because ansible lists it as a requirement. Previously
  the missing dep wasn't enforced, but cryptography imports pkg_resources
  so you can't ignore a requirement any more

* Add integration test cases for old vault and for wrong passwords

* helper script for manual testing of pycrypto/cryptography

* Skip the pycrypto tests so that users without it installed can still run the unittests

* Run unittests for vault with both cryptography and pycrypto backend
7 years ago
loqutus 8edcef7a84 fix comment in inventory/digital_ocean.py (#25828) 7 years ago
Abhijeet Kasurde b89cb95609 Fix spelling mistakes (comments only) (#25564)
Original Author : klemens <ka7@github.com>

Taking over previous PR as per
https://github.com/ansible/ansible/pull/23644#issuecomment-307334525

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
7 years ago
Carsten Clasohm cd31f4a102 foreman.py: create Ansible groups from Satellite 6 host collections (#25269)
* create Ansible groups from host collections

* fix paging logic in _get_json

* replace Satellite with Foreman

* improve comment for environment variables

* enable host collections by default

* use requests params instead of urllib.quote_plus

* disable host collections by default

* change organization filter

* clean up load_cache methods

* remove usage of function defaults

* replace environment variables with host_filters
7 years ago
James Elford bc9dbf38b0 python 3 compatibility: import guard around ConfigParser
In python3 `ConfigParser` has become `configparser`. Added
an import guard that aliases it back to the old name.
7 years ago
Eric L eb53f3c129 Fix inventory script for Foreman where group by pattern are not prope… (#25173)
* Fix inventory script for Foreman where group by pattern are not properly safe-guarded.

* Fix pep8 error about tab mixed with blanks.
7 years ago
Sloane Hertel e67cdd448e [cloud] EC2 dynamic inventory default filename is documented as ec2.ini - fixes #24396 (#24515)
* the default filename is ec2.ini

(to override that use the env var EC2_INI_PATH)

* allow fallback to ec2.ini
7 years ago
Dag Wieers 758cfeb73e contrib: PEP8 compliancy (#24680)
- Make PEP8 compliant
7 years ago
Abhijeet Kasurde 3a82246d82 Misc typo fix in fleet inventory (#25174)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
7 years ago
Michael b65ebf3519 Fixed import of urlencode and pathname2url from urllib for python3 (#24424) 7 years ago
Jorge Quintás d3c94e82a5 take into account if cache file exists when loading data from digitalocean even with --force-cache 7 years ago
Matt Martz d3249e7875 pep8 fixes for contrib (#24344) 7 years ago
Elijah Lynn c7ae6b9fd5 [cloud][inventory] Get tags for RDS instances. (#23989)
* Get tags for RDS instances.

Boto3 only at this time.

Relates to #11569, #14464.

* Add a check for boto3

* Fix HAS_BOTO3 error
7 years ago
Ondra Machacek 2c58ac1833 inventory: ovirt4: Add support for devices without IP (#24287) 7 years ago
Tom Melendez 9d5c399313 Added subnetwork parameter to inventory instance dictionary. (#23984) 7 years ago
Matt Clay 48eeab8a53 Fix errors reported by pylint. (#23282)
* Fix pylint misplaced-bare-raise errors.
* Fix pylint return-in-init error.
* Fix pylint bad-format-character error.
* Fix pylint too-many-format-args errors.
* Fix pylint too-few-format-args errors.
* Fix pylint truncated-format-string error.
7 years ago
Toshio Kuratomi 6bad4e57bd Migrate most uses of if type() to if isinstance()
Also convert those checks to use abcs instead of dict and list.

Make a sentinel class for strategies to report when they've reache the end
7 years ago
Wayne Witzel III 1a1e12cf46 fetch spacewalk.ini from the environment if set 7 years ago
Tim Rupp 2d8c5e6b8f [openstack] Adds the non-deprecated ansible_host var (#23153)
OpenStack dynamic inventory is still using the deprecated
ansible_ssh_host. This patch adds ansible_host until such
time as ansible_ssh_host is removed
7 years ago
rafstef 25019fe70c Fix vmware property filter (#23228)
Fixes errors on properties that do not exist.
7 years ago
Matt Martz 495a1340a6 Address lxd inventory pep8 error (#23021) 7 years ago
Francisco Ros 0fa797030e Brook inventory (#16122)
* Do not ask for templates in Brook inventory if they do not exist

* Add availability zone variable to Brook inventory

* Add provider id variable to Brook inventory

* Error output sent to stderr in Brook inventory
7 years ago
Andrew Clarke 73438de862 A basic lxd dynamic inventory script (#15848)
* A basic start on an lxd dynamic inventory script

The script is a fairly basic start on an lxd dynamic inventory script. Only tested on ubuntu 16.04 and currently only reports ipv4 container addresses. Improvements to come.

* Updated formatting, indenting and python3 support

Updated to work on python3

* Additional options read from the ini file

Added options for connection and group to the ini file and modified to use these.

Host returned is now the name by default. For non-lxd connection, the ansible_host var is populated with the ip address.

* Additional options for group and connection

* Minor change to re-run tests
7 years ago
Toshio Kuratomi 2fff690caa Update module_utils.six to latest (#22855)
* Update module_utils.six to latest

We've been held back on the version of six we could use on the module
side to 1.4.x because of python-2.4 compatibility.  Now that our minimum
is Python-2.6, we can update to the latest version of six in
module_utils and get rid of the second copy in lib/ansible/compat.
7 years ago
Steve Kuznetsov 6318229bc4 Only read EC2 `regions_exclude` list if necessary (#18720)
When specifying a literal whitelist of AWS EC2 regions in the dynamic
inventory configuration file, it should not be necessary to also include
a literal blacklist, especially as the blacklist is not honored in this
case anyway. By reading the literal blacklist only when necessary, it is
possible for a user to provide a more minimal EC2 configuration file.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
7 years ago
Rune T. Sorensen 6804d69557 [cloud][contrib] IAM role support for EC2 dynamic inventory (#15196)
* EC2 inventory can now connect using an IAM role

* Fix comment indentation

* Make sure that Ec2Inventory.iam_role is always defined

* Add missing import
7 years ago
jctanner 447bb2b150 Add a custom regex_match filter to the vmware_inventory script (#21488) 7 years ago
Markus Liljedahl 67dc8c146e Added support for specifying zone for gce dynamic inventory (#20938) 7 years ago
William Holroyd 4ca7726e75 Fix Elasticcache issue where ec2 script would fail on finding lack of primary endpoint address on Redis cluster (#20190) 7 years ago
Ondra Machacek 0433be33bd ovirt: dyn_inventory fix Python2 and Python3 compat (#22453) 7 years ago
Matt Davis cbedc4a12a azure_rm inventory version comparison fix (#22341) 7 years ago
Damien 2376d891c7 [inventory/aos] Few fixes and small tweaks (#22259)
* Add ads server itself as an host in the inventory

* Comment all value in example

* Add Id in variable list per device

* Centralize code to add device status to variables

* Fix device variable name for blueprint
7 years ago
Damien 8032c9a715 Clean up group name before creation to remove spaces etc .. (#22020) 7 years ago
René Moser 87119479d8 cloudstack: fix pep8 cloudstack inventory (#22092) 7 years ago