First you need Download ec2.py and ec2.ini to /etc/ansible/
url this here
https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.ini
https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py
Then,we need change ec2.ini, uncomment this line
elasticache = False
whether, when you run ec2.py --list ,you maybe got this errors
ERROR: "Forbidden", while: getting ElastiCache clusters
and this is my ec2.ini, you can copy it to you environment
[ec2]
regions = all
regions_exclude = us-gov-west-1, cn-north-1
destination_variable = private_dns_name
hostname_variable = tag_Name
vpc_destination_variable = private_ip_address
route53 = False
elasticache = False
all_instances = False
all_rds_instances = False
include_rds_clusters = False
all_elasticache_replication_groups = False
all_elasticache_clusters = False
all_elasticache_nodes = False
cache_path = ~/.ansible/tmp
cache_max_age = 300
nested_groups = False
replace_dash_in_groups = True
expand_csv_tags = False
group_by_instance_id = True
group_by_region = True
group_by_availability_zone = True
group_by_aws_account = False
group_by_ami_id = True
group_by_instance_type = True
group_by_instance_state = False
group_by_platform = True
group_by_key_pair = True
group_by_vpc_id = True
group_by_security_group = True
group_by_tag_keys = True
group_by_tag_none = True
group_by_route53_names = True
group_by_rds_engine = True
group_by_rds_parameter_group = True
group_by_elasticache_engine = True
group_by_elasticache_cluster = True
group_by_elasticache_parameter_group = True
group_by_elasticache_replication_group = True
stack_filters = False
[credentials]
Then, we can use it command list tag Name is stage-app’s server
ansible -i ec2.py tag_Name_stage_app* --list-host #syntax is tag_KEY_VALUE
ansible-inventory --graph -i ec2.py
网友评论