簡體   English   中英

EC2動態清單-按VPC ID過濾實例

[英]EC2 Dynamic Inventory - Filtering Instances by VPC ID

我在Ubuntu 16.04內核4.4.0的Python 3.5.2下的Ansible 2.4.2.0上。

我已經下載了EC2廣告資源Python腳本 ,並使用ec2.ini對其進行了配置, ec2.ini所示:

[ec2]
regions = all
regions_exclude = us-gov-west-1,cn-north-1
destination_variable = private_dns_name
vpc_destination_variable = private_ip_address
route53 = True
rds = 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 = True
replace_dash_in_groups = True
expand_csv_tags = True
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_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
instance_filters = vpc-id=vpc-deadbeef

[credentials]

我的清單目錄inventory/development包含以下內容:

inventory/development/
├── ec2.ini
├── ec2.py
└── hosts

我的主機文件如下所示:

[tag_atlas_project_manager]

[manager:children]
tag_atlas_project_manager

我的ansible.cfg

[defaults]
retry_files_enabled = false
roles_path = galaxy_roles:roles
inventory = inventory/
timeout = 120

[ssh_connection]
pipelining = True
ssh_args = -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ControlMaster=auto -o ControlPath=~/.ssh/mux-%r@%h:%p -o ControlPersist=8h

好的,我的VPC vpc-deadbeef的配置如下:

$ aws ec2 describe-vpcs | \
    jq -r '.Vpcs[] | { Id: .VpcId, CidrBlock: .CidrBlock } | select(.CidrBlock == "10.50.0.0/16")'
{
  "CidrBlock": "10.50.0.0/16",
  "Id": "vpc-deadbeef"
}

運行清單腳本時,沒有任何超出此范圍的IP地址:

$ inventory/development/ec2.py --list | \
    grep -ioP '10\.\d{1,3}\.\d{1,3}.\d{1,3}' | sort -u
10.50.10.10
...

但是,當我對all運行一個劇本時,我看到vpc-deadbeef之外的主機:

$ ansible -i inventory/development/ -f 30 all -m command -a true
...

10.1.30.110 | UNREACHABLE! => {
    "changed": false,
    "msg": "SSH Error: data could not be sent to remote host \"10.1.30.110\". Make sure this host can be reached over ssh",
    "unreachable": true
}
10.1.30.250 | UNREACHABLE! => {
    "changed": false,
    "msg": "SSH Error: data could not be sent to remote host \"10.1.30.250\". Make sure this host can be reached over ssh",
    "unreachable": true
}

是什么賦予了? 我究竟做錯了什么?

事實證明, inventory/development中還有另一個子目錄,其中也有一個ec2.ini ,這個清單文件在運行過程中被Ansible 合並

$ ansible -vvv -i inventory/development/ -u grindr all -m command -a 'true'
ansible 2.4.2.0
  config file = ansible.cfg
  configured module search path = ['/home/naftuli/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
Using ansible.cfg as config file
Parsed inventory/development/ec2.py inventory source with script plugin
Parsed inventory/development/hosts inventory source with ini plugin
Parsed inventory/development/preprod/ec2.py inventory source with script plugin
Parsed inventory/development/preprod/hosts inventory source with ini plugin

這就是Ansible遞歸爬升的問題,我認為這是有道理的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM