我使用ansible创建了一个ec2实例但是在创建实例之后它没有下载git包。 我的代码:
ec2:
key_name: "{{ key }}"
aws_access_key: "{{ aws_id }}"
aws_secret_key: "{{ aws_key }}"
region: "{{ aws_region }}"
image: ami-2322b6123
instance_type: t2.micro
- name: install git
yum: name=git state=present
所以,我可以知道在使用ansible创建ec2实例后是否有办法安装包?
答案 0 :(得分:1)
启动EC2实例后,您必须在新启动的实例中运行播放(安装git),而不是在控制主机中运行。您必须注册刚刚启动的,将其添加到主机库存,然后安装包。只需按照Ansible文档中的示例进行操作:ec2 module
- name: Create a instance
...
...
tasks:
- name: Launch instance
ec2:
key_name: "{{ key }}"
aws_access_key: "{{ aws_id }}"
aws_secret_key: "{{ aws_key }}"
region: "{{ aws_region }}"
image: ami-2322b6123
instance_type: t2.micro
register: ec2
- name: Add new instance to host group
add_host: hostname={{ item.public_ip }} groupname=launched
with_items: '{{ec2.instances}}'
- name: Wait for SSH to come up
wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started
with_items: '{{ec2.instances}}'
- name: Configure instance(s)
hosts: launched
gather_facts: True
...
tasks:
- name: install git
yum: name=git state=present