ec2 인스턴스를 생성하고 호스트를 동적 호스트로 추가 할 수있는 작업을 작성했습니다. 작업이 완벽하게 작동하고 인스턴스를 만들었지 만 인스턴스 정보를 검색 할 수 없습니다.가능성있는 EC2 모듈이 인스턴스 정보를 검색하지 않습니다.
는내 Ansible 버전 : 2.2.0.0/우분투 여기 14.04
내 코드
- name: launch ec2 instance for QA
local_action:
module: ec2
key_name: "{{ ec2_keypair }}"
group: "{{ ec2_security_group }}"
instance_type: "{{ ec2_instance_type }}"
image: "{{ ec2_image }}"
vpc_subnet_id: "{{ ec2_subnet_ids }}"
region: "{{ ec2_region }}"
instance_tags: '{"Name":"{{ec2_tag_Name}}","Type":"{{ec2_tag_Type}}","Environment":"{{ec2_tag_Environment}}"}'
assign_public_ip: yes
wait: true
count: 1
register: ec2
- debug: var=item
with_items: ec2.instances
- add_host: name={{ item.public_ip }} >
groups=dynamically_created_hosts
with_items: ec2.instances
- name: Wait for the instances to boot by checking the ssh port
wait_for: host={{item.public_ip}} port=22 delay=60 timeout=320 state=started
with_items: ec2.instances
입니다 얻고 무엇을 출력은 다음과 같습니다
TASK [QA에 대한 발사 EC2 인스턴스] ************************************
변경됨 : [localhost -> localhost]TASK [디버그] ********************************************** *********************
ok : [localhost] => (item = ec2.instances) => { "item": "ec2.instances " }TASK [add_host] *************************************** ************************
치명적 : [localhost] : FAILED! => { "failed": true, "msg": "필드 'args'에 정의되지 않은 변수가 포함 된 잘못된 값이 있습니다. 'unicode object'에 'public_ip'속성이 없습니다. \ n \ n 오류는 '/var/lib/jenkins/jobs/QA/workspace/dynamic-ec2.yml': 줄 37, 7 열에 있지만 정확한 구문 문제에 따라 파일의 다른 위치에 \ n있을 수 있습니다. \ n \ n 문제가되는 행은 다음과 같이 표시됩니다. \ n \ n \ n - add_host : name = {{item.public_ip}}> \ n^여기 \ n 잘못 될 수도 있지만 문제가 될 수 있습니다. \ n \ n with_items : \ n - {{foo}} \ n \ n 다음과 같이 써야합니다 : \ n \ n with_items : \ n - \ "{{foo}} \"\ n "}
다른 방법이 있습니까?
@tehraf 귀하의 조언에 감사드립니다. 완벽하게 작동합니다. – rolindroy