Commit graph

81 commits

Author SHA1 Message Date
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
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
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
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
Sebastian Cruz
223f94ec56 Fix missing option in #27848 (#27892) 2017-08-09 08:41:12 -04:00
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
2017-08-07 12:45:04 -06:00
Adam Johnson
3f85aa3abd Use a real list comprehension rather than list() around a generator (#25594)
It's faster and more idiomatic.
2017-08-07 12:30:01 -06:00
Tian You
9364fa202f [cloud] Group RDS instances by tag keys in ec2 dynamic inventory (#24763) 2017-08-04 14:38:04 -04:00
Josh Smift
290d84f904 Update ansible_ssh_host->ansible_host in ec2.py dynamic inventory (#17113) 2017-07-17 15:30:11 -04:00
Brian Coca
365f3dc9d9 switched to elif 2017-07-05 11:02:47 -04:00
Lorin Hochstein
b17da1fae9 ec2.py: Better error messages for OptInRequired
Improve error messages for RDS and ElastiCache failures for code OptInRequired.
2017-07-05 11:02:10 -04:00
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>
2017-06-12 07:55:19 +01:00
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
2017-05-31 14:59:55 -04:00
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