1
나는 ec2 인스턴스를 자동화 할 수있는 능력이 있습니다. ec2 인스턴스를 만든 다음 ec2_remote_facts 모듈을 통해 공용 DNS 이름을 가져 오려고합니다. 그러나 출력에 정의되지 않은 변수를 제공합니다.ec2 인스턴스를 얻으려면 어떻게해야합니까?
playbook:
- hosts: localhost
connection: local
tasks:
- name: ec2 instance facts
ec2_remote_facts:
region: ap-southeast-2
filters:
instance-state-name: running
register: ec2
- debug: var=ec2.instances.public_name
Output:PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [create ec2 instance] *****************************************************
ok: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
"ec2.instances.public_name": "VARIABLE IS NOT DEFINED!"
}
PLAY RECAP *********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
Output for ec2.instances.
ok: [localhost] => {
"ec2.instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"client_token": "",
"ebs_optimized": false,
"groups": [
{
"id": "sg-6c016a08",
"name": "default"
}
],
"hypervisor": "xen",
"id": "i-915b1813",
"image_id": "ami-fedafc9d",
"instance_profile": null,
"interfaces": [
{
"id": "eni-96de4acf",
"mac_address": "0a:14:ac:64:c4:13"
}
],
"kernel": null,
"key_name": "ansible.key",
"launch_time": "2016-08-29T07:32:10.000Z",
"monitoring_state": "disabled",
"persistent": false,
"placement": {
"tenancy": "default",
"zone": "ap-southeast-2c"
},
"private_dns_name": "ip-xx-xx-xx-107.ap-southeast-2.compute.internal",
"private_ip_address": "xx.xx.xx.107",
"public_dns_name": "ec2-xx-xxx-xx-80.ap-southeast-2.compute.amazonaws.com",
"ramdisk": null,
"region": "ap-southeast-2",
"requester_id": null,
"root_device_type": "ebs",
"source_destination_check": "true",
"spot_instance_request_id": null,
"state": "running",
"tags": {
"Name": "Demo"
},
"virtualization_type": "hvm",
"vpc_id": "vpc-abcaf4ce"
}
]
}
여기에 무엇이 누락 되었습니까? 당신이 ec2.instances
에 자세히 보면
감사
Benjo
친숙한 조언 :'dict1.var1.var2' 변수가 정의되지 않은 경우'dict1.var1'의 내부를 검사하여'var2'를 사용할 수없는 이유를 확인하십시오. –
업데이트 된 게시물을 ec2.instances 출력 – Ben