Ansible | EC2设置和配置

时间:2018-09-05 18:48:17

标签: amazon-ec2 ansible

我正在尝试创建EC2实例,并希望配置一些工具,例如apache。我能够使用Ansible剧本创建实例,但在安装Apache时出错。

错误:

root@ip:/etc/ansible# ansible-playbook ec2.yml -vvv

ansible-playbook 2.6.3
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', 
u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 
20160609]
Using /etc/ansible/ansible.cfg as config file
Parsed /etc/ansible/hosts inventory source with script plugin
ERROR! no action detected in task. This often indicates a misspelled module 
name, or incorrect module path.

The error appears to have been in '/etc/ansible/roles/ec2/tasks/main.yml': 
line 25, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: configure instances
^ here

我的剧本:

---
- name: Provision instance
  hosts: localhost
  become: true
  roles:
    - ec2

ec2角色下的任务-

---
- name: Launch Instance
  ec2:
    key_name: "{{ key_name }}"
    group: "{{ security_group }}"
    instance_type: "{{ instance_type }}"
    image: "{{ image }}"
    wait: true
    region: "{{ region }}"
    count: 1
    vpc_subnet_id: subnet-26f7fd7c
    assign_public_ip: yes
  register: ec2


- name: Add new instance to host group
  add_host:
    hostname: "{{ item.public_ip }}"
    groupname: mygroup
  with_items: "{{ ec2.instances }}"

- name: Wait for SSH to come up
  pause: minutes=1

- name: configure instances
  hosts: mygroup
  become: yes
  roles:
    - apache

我在这里重用Apache角色。

和变量是:

 ---
 # vars file for ec2
 key_name: Testmachine
 instance_type: t2.micro
 security_group: launch-wizard-1
 image: ami-04169656fea786776
 region: us-east-1

1 个答案:

答案 0 :(得分:0)

您命名为configure instances的代码段是一种玩耍,而不是一项任务。

您不能在角色的tasks下使用它。


您应将其添加到您的剧本(剧本):

---
- name: Provision instance
  hosts: localhost
  become: true
  roles:
    - ec2

- name: configure instances
  hosts: mygroup
  become: yes
  roles:
    - apache