Commit graph

67 commits

Author SHA1 Message Date
Matt Martz
d3249e7875 pep8 fixes for contrib (#24344) 2017-05-09 16:38:08 -05:00
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
2017-05-09 16:56:54 -04:00
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
2017-04-04 08:17:20 -07:00
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>
2017-03-22 09:31:58 -04:00
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
2017-03-20 17:19:40 -04:00
William Holroyd
4ca7726e75 Fix Elasticcache issue where ec2 script would fail on finding lack of primary endpoint address on Redis cluster (#20190) 2017-03-10 13:08:54 -05:00
Alex Trevino
0d060a185f Allow ec2.py to be imported (#21637) 2017-02-20 15:19:05 -05:00
rafstef
8acb6417cb [cloud][inventory] Let ec2.py be renamed and search for a matching .ini file (#21567)
With this proposed PR, we want to make the use of many ec2 dynamic inventory files more flexible.
We are using multiple AWS accounts. We want to use different ini file (one for every account) and only one ec2.py.
2017-02-20 13:38:41 -05:00
Ryan S. Brown
3c25a39b3e [cloud][aws] Use binary read for inventory cache file 2017-02-16 09:42:46 -05:00
Alex Trevino
413dfa7273 [cloud][aws] Use with statement for file rw in EC2 dynamic inventory (#21390)
* Use with statement when doing rw on files

* Deserialize file-like object directly instead of a string

For python 2/3 compatibility reasons, per PR feedback.
2017-02-16 09:41:55 -05:00
Jonathan McCall
047ed2728c Pass boto_profile to get_route53_records (#14354)
* Pass boto_profile to get_route53_records

* Add conditional around r53_conn to check for boto_profile
2017-02-16 08:49:47 -05:00
Ian White
80bc7048bd Feature: adding route53_hostnames option to set the hostnames from route 53 (#20909)
* adding route53_hostnames option to set the hostnames from route 53

* checking whether the route53_hostnames option is present as suggested by @s-hertel

* setting route53_hostnames to None when config option not present

* skip the to_safe only when using route53_hostnames option, as suggested by @ryansb

* skipping the to_safe strip only for the hostnames that came from route53 as suggested by @ryansb
2017-02-14 10:50:41 -05:00
gregorydulin
cf424f0413 [cloud] Add group_by_instance_state to EC2 Dynamic Inventory (#20430) 2017-02-14 10:27:19 -05:00
Ilya Kalinin
259b05dd8e [cloud] Add stack_filters option to EC2 inventory script 2017-02-09 09:13:10 -05:00
Matt Martz
5942de603d Legacy pep8 clean fixes for contrib and hacking (#21081) 2017-02-07 09:49:55 -06:00
Matt Clay
e401b4e424 PEP 8 fix. 2017-02-01 08:24:31 -08:00
Naoya Nakazawa
31db1bcd34 ec2.py support region auto (#15427) 2017-02-01 09:08:15 -05:00
Will Thames
d6ea400efb Improve boto profile handling for EC2 inventory (#20280)
Ensure command line profile argument and AWS_PROFILE environment variable
overrides config file
Remove unnecessary `lambda` function
Fix cache file path construction to be more pythonic (and windows-ready)
2017-01-31 09:35:45 -05:00
Matt Clay
cb76200c7d PEP 8 E111 & E114 cleanup. (#20838) 2017-01-30 15:01:47 -08:00
Matt Clay
d0d1158c5e PEP 8 cleanup. (#20789)
* PEP 8 E703 cleanup.
* PEP 8 E701 cleanup.
* PEP 8 E711 cleanup.
* PEP 8 W191 and E101 cleanup.
2017-01-28 00:12:11 -08:00
Matthew Wedgwood
3ab388f6dd Add account ID grouping and attribute to ease multi-account management 2017-01-23 13:49:02 -05:00
Carlos E. Garcia
0b8011436d minor spelling changes 2016-12-13 13:51:13 -05:00
Tony Kinsley
73da2663a3 Resolves #18312 python3 support for ec2.py 2016-11-03 11:46:50 -07:00
Khushil Dep
08db04ccb6
Changes as per @abadger 2016-09-14 15:11:57 +01:00
Khushil Dep
054e640fba
Add enumeration of block devices to ec2_block_devices 2016-09-14 15:11:57 +01:00
Ryan S. Brown
0783c172d7 Paginate DB cluster responses in AWS RDS dynamic inventory 2016-08-15 14:27:48 -04:00
Ryan S. Brown
59e499f8f0 Respect profiles & credentials for boto3 inventory
Using boto3 directly wasn't properly using profiles set in the `ec2.ini`
file, this change uses the `module_utils` boto3_conn instead.
2016-07-06 10:57:31 -04:00
Tom Paine
418f91d0e2 Fail softly when boto3 is not installed
Updated as per @ryansb comments. The EC2 inventory script will now fail
with a useful message when boto3 is not installed and the user is trying
to read RDS cluster information.
2016-07-06 10:57:31 -04:00
Tom Paine
bb5a1f7440 Add RDS cluster info to EC2 dynamic inventory
Add db_clusters to the ec2 inventory. Show tags. Only show clusters
matching tags in the `.ini`. Set `include_rds_clusters = True` option to
enable RDS cluster inventory collection.

Example inventory output:

```
{
  "db_clusters": {
    "ryansb-cluster-test": {
      "AllocatedStorage": 1,
      "AvailabilityZones": [
        "us-west-2a",
        "us-west-2b",
        "us-west-2c"
      ],
      "BackupRetentionPeriod": 1,
      "DBClusterIdentifier": "ryansb-cluster-test",
      "DBClusterMembers": [
        {
          "DBClusterParameterGroupStatus": "in-sync",
          "DBInstanceIdentifier": "ryansb-test",
          "IsClusterWriter": true,
          "PromotionTier": 1
        },
        {
          "DBClusterParameterGroupStatus": "in-sync",
          "DBInstanceIdentifier": "ryansb-test-us-west-2b",
          "IsClusterWriter": false,
          "PromotionTier": 1
        }
      ],
      "DBClusterParameterGroup": "default.aurora5.6",
      "DBSubnetGroup": "default",
      "DatabaseName": "mydb",
      "DbClusterResourceId": "cluster-OB6H7JQURFKFD4BYNHG5HSRLBA",
      "Endpoint": "ryansb-cluster-test.cluster-c9ntgaejgqln.us-west-2.rds.amazonaws.com",
      "Engine": "aurora",
      "EngineVersion": "5.6.10a",
      "MasterUsername": "admin",
      "Port": 3306,
      "PreferredBackupWindow": "06:09-06:39",
      "PreferredMaintenanceWindow": "mon:11:22-mon:11:52",
      "ReadReplicaIdentifiers": [],
      "Status": "available",
      "StorageEncrypted": false,
      "VpcSecurityGroups": [
        {
          "Status": "active",
          "VpcSecurityGroupId": "sg-47eaea20"
        }
      ]
    }
  },
  "rds": [
    "ryansb_test_c9ntgaejgqln_us_west_2_rds_amazonaws_com",
    "ryansb_test_us_west_2b_c9ntgaejgqln_us_west_2_rds_amazonaws_com"
  ],
  "rds_aurora": [
    "ryansb_test_c9ntgaejgqln_us_west_2_rds_amazonaws_com",
    "ryansb_test_us_west_2b_c9ntgaejgqln_us_west_2_rds_amazonaws_com"
  ],
  "rds_parameter_group_default_aurora5_6": [
    "ryansb_test_c9ntgaejgqln_us_west_2_rds_amazonaws_com",
    "ryansb_test_us_west_2b_c9ntgaejgqln_us_west_2_rds_amazonaws_com"
  ],
  "ryansb-test": [
    "ryansb_test_c9ntgaejgqln_us_west_2_rds_amazonaws_com"
  ],
  "ryansb-test-us-west-2b": [
    "ryansb_test_us_west_2b_c9ntgaejgqln_us_west_2_rds_amazonaws_com"
  ],
  "type_db_r3_large": [
    "ryansb_test_c9ntgaejgqln_us_west_2_rds_amazonaws_com",
    "ryansb_test_us_west_2b_c9ntgaejgqln_us_west_2_rds_amazonaws_com"
  ],
  "us-west-2": [
    "ryansb_test_c9ntgaejgqln_us_west_2_rds_amazonaws_com",
    "ryansb_test_us_west_2b_c9ntgaejgqln_us_west_2_rds_amazonaws_com"
  ],
  "us-west-2a": [
    "ryansb_test_c9ntgaejgqln_us_west_2_rds_amazonaws_com"
  ],
  "us-west-2b": [
    "ryansb_test_us_west_2b_c9ntgaejgqln_us_west_2_rds_amazonaws_com"
  ],
  "vpc_id_vpc_3ca34459": [
    "ryansb_test_c9ntgaejgqln_us_west_2_rds_amazonaws_com",
    "ryansb_test_us_west_2b_c9ntgaejgqln_us_west_2_rds_amazonaws_com"
  ]
}
```
2016-07-06 10:57:31 -04:00
bqbn
3498b840c9 Fixes #16095: Maximumly 199 filter values (#16184)
When making calls to AWS EC2 api with DescribeTags actiion and if the
number of filter values is greater than or equal to 200, it results in
400 bad request reply and the error message is:
"Error connecting to AWS backend.\n The maximum number of filter values specified on a single call is 200".

The change is so that we call get_all_tags with maximum 199 filter
values one at a time until all are consumed.
2016-06-13 11:19:42 -04:00
Adam Chainz
064ed63843 Fix ec2 inventory for potentially inconsistent data (#12642) 2016-05-24 11:00:59 -04:00
Victor Costan
8d3da09eae contrib/inventory/ec2.py can read AWS credentials from ec2.ini (#15378) 2016-05-20 09:29:15 -04:00
Jorge Nerín
3a3e69f830 Fix substituting dots for underscores when using ips (#15578)
ec2.py was substituting the dots on ip addresses when not using hostnames like:
  "ec2": [
    "10_10_1_1", 

now it's:
  "ec2": [
    "10.10.1.1",
2016-04-25 10:22:00 -04:00
Owen Tuz
3b8d753121 Avoid cache conflicts when using multiple AWS accounts 2016-03-21 14:58:55 +00:00
James Cammarata
c9da48d5ba Merge branch 'destination_format' of https://github.com/a13m/ansible into a13m-destination_format 2016-03-19 09:05:14 -04:00
Brian Coca
e1ee2ed5a5 Merge pull request #13550 from KrzysiekJ/connect_to_region-wrap
Use wrapped connect_to_region everywhere in ec2.py
2016-03-18 21:25:55 -07:00
Brian Coca
eceabec71f page rds instances
fix #14861
2016-03-18 13:31:52 -07:00
Abhijit Menon-Sen
ad0e707f97 Merge pull request #7395 from hkariti/ec2_hostname_variable
Add hostname_variable to ec2 inventory script
2016-03-18 15:37:00 +05:30
Hagai Kariti
8a17da299f Clean up lines with only whitespaces in ec2.py 2016-03-17 20:06:01 +02:00
Hagai Kariti
53756af546 Added hostname_variable to ec2 inventory 2016-03-17 20:06:00 +02:00
Abhijit Menon-Sen
f0af07a5f4 Merge pull request #14761 from enbritely/fix-ec2-inventory
Fix AWS EC2 inventory script instance_filters read
2016-03-17 21:51:43 +05:30
Joe
21ba6e9ce8 Do not use name tag for intance filter 2016-03-02 20:06:14 +01:00
Joe
5975296770 Fix AWS EC2 external inventory script config read
EC2 inventory scripts reads configuration from an INI file. The `instance_filters` option controls which EC2 instances are retrieved for inventory. Filling this option and running the inventory script with Python 3 crashes with the following error:

```python
Traceback (most recent call last):
  File "./contrib/inventory/ec2.py", line 1328, in <module>
    Ec2Inventory()
  File "./contrib/inventory/ec2.py", line 163, in __init__
    self.read_settings()
  File "./contrib/inventory/ec2.py", line 393, in read_settings
    for instance_filter in config.get('ec2', 'instance_filters', '').split(','):
TypeError: get() takes 3 positional arguments but 4 were given
```

The problem is the last parameter of config.get() call, because `fallback` keyword argument is not specified.

The fix handles epmpty `instance_filers` in case of Python 2&3
2016-03-02 19:44:25 +01:00
Brian Coca
37eac4592e added back --profile to keep backwards compat
this was broken by #12548
2016-01-30 11:35:11 -05:00
Krzysztof Jurewicz
73160e65e5 Use wrapped connect_to_region everywhere in ec2.py 2015-12-15 12:03:50 +01:00
Abhijit Menon-Sen
e6a9b2cae5 Add an expand_csv_tags setting to ec2.ini
If enabled, this will convert tags of the form "a,b,c" to a list and use
the results to create additional inventory groups.

This is based on PR #8676 by nickpeck (but not a straight rebase—both
the code and the nomenclature have been changed here).

Closes #8676
2015-11-12 08:48:53 +05:30
Brian Coca
b2a9111b22 reversed the logic on new setting to control - replacment in groups as
it was wrong
fixes #13122
2015-11-11 13:35:09 -08:00
Matthew Jones
faeccb4e61 Fix ec2 infinitely nested groups
The ec2 inventory module will incorrectly place parent groups as child
groups of themselves, this fixes that.
2015-10-29 13:24:39 -04:00
Brian Coca
2b8633cec0 Merge pull request #12855 from bcoca/ec2_inv_dash_group
make - replacement in group names optional
2015-10-26 13:28:35 -04:00
Brian Coca
aac20aa076 removed unused exception vars 2015-10-21 22:29:27 -04:00