
로컬 구성과 Amazon Auto-Scaling 그룹을 생성했습니다. 이 코드를 사용하면 됩니다.
---
-
local_action:
image_id: ami-61f9324
instance_type: t2.micro
module: ec2_lc
name: nice-lc
region: us-west-2
security_groups: launch-wizard-1
name: "Create lc"
-
local_action:
desired_capacity: 2
health_check_period: 5
health_check_type: ELB
launch_config_name: nice-lc
load_balancers: nice-lb1
max_size: 10
min_size: 2
module: ec2_asg
name: nice-asg
region: us-west-2
name: "Create asg"
나는 재고용으로 ec2.py
및 파일을 사용하고 있습니다.ec2.ini
이제 로컬 구성 및 Auto-scaling 그룹이 생성되고 정의한 원하는 용량에 따라 2개의 인스턴스가 시작됩니다.
이제 해당 2개의 인스턴스에서 작업을 실행하고 싶습니다.
이를 위해 나는 이 yaml 파일을 사용하고 있습니다.
---
- name: Example of provisioning servers
hosts: 127.0.0.1
connection: local
tasks:
- name: Add EP2 instances to host group
local_action: add_host hostname={{ ec2_publicIp }} groupname=launch-wizard-1
with_items: ec2.instances
- name: Add tag to instances
local_action: ec2_tag resource={{ item.id }} region=us-west-2 state=present
with_items: ec2.instances
args:
tags:
Name: nice-ec2
- name: Wait for SSH to be available
pause: minutes=1
- name: Configure provisioned servers
hosts: tag_aws_autoscaling_groupName_nice_asg
user: ubuntu
sudo: True
gather_facts: True
tasks:
- name: restart nginx
service: name=nginx state=restarted
이 파일을 실행하면 오류가 발생합니다.
하나 이상의 정의되지 않은 변수: 'ec2_publicIp'가 정의되지 않았습니다.
질문:
nginx를 다시 시작하고 Amazon Auto-Scaling 그룹에서 시작한 인스턴스에 태그를 추가하는 등의 작업을 실행하고 싶습니다.
내가 제대로 하고 있는 걸까? asg가 시작한 인스턴스에서 일부 작업을 실행하려는 경우 호스트에 추가할 필요조차 없는 것 같습니다.
답변1
'호스트 그룹에 EP2 인스턴스 추가' 작업 위에서 다음을 사용하세요.
- debug: var=ec2
변수가 무엇을 가지고 있는지 확인하십시오. 각 인스턴스의 변수를 살펴보면 ec2_publicIP 철자가 잘못되었거나 변수의 다른 위치에 있음을 알 수 있습니다.
답변2
asg가 시작한 인스턴스에서 명령을 실행하고 싶습니다.
---
# I have removed that code and just using this.
# This works with instance launched by asg.
- name: Configure provisioned servers
hosts: tag_aws_autoscaling_groupName_nice_asg
user: ubuntu
sudo: True
gather_facts: True
tasks:
- name: restart nginx
service: name=nginx state=restarted