我创建了一个游戏手册 aws.yml 并想通过我的本地主机运行它
---
- hosts: webserver
- vars:
region: ap-south-1
instance_type: t2.micro
ami: ami-005956c5f0f757d37 # Amazon linux LTS
keypair: ansible # pem file name
- tasks:
- ec2:
key_name: "{{ ansible }}"
group: ansible # security group name
instance_type: "{{ t2.micro }}"
image: "{{ ami-005956c5f0f757d37 }}"
wait: true
wait_timeout: 500
region: "{{ ap-south-1 }}"
count: 1 # default
count_tag:
Name: Prod-Instance
instance_tags:
Name: Prod-Instance
vpc_subnet_id: subnet-00efd068
assign_public_ip: yes
主机文件的内容 等可控主机
[web]
localhost
当我试图运行我的 aws.yml它给出了以下错误信息
[root@localhost ~]# ansible-playbook aws.yml
PLAY [web] ********************************************************************************************************************************************************************************************************
ERROR! the field 'hosts' is required but was not set
[root@localhost ~]#
你的游戏本和你的主机组名称不匹配。
在 aws.yml
- hosts: webserver
而在 等可控主机
[web]
你应该改变你的 aws.yml 读本
- hosts: web
或 您的主机文件 等可控主机 阅读
[webserver]
太多了 -
s. 去掉前面的 tasks
和 vars
.
另外,使用 delegate_to: localhost
在...上 ec2
任务。
---
- hosts: webserver
vars:
region: ap-south-1
instance_type: t2.micro
ami: ami-005956c5f0f757d37 # Amazon linux LTS
keypair: ansible # pem file name
tasks:
- ec2:
key_name: "{{ ansible }}"
group: ansible # security group name
instance_type: "{{ t2.micro }}"
image: "{{ ami-005956c5f0f757d37 }}"
wait: true
wait_timeout: 500
region: "{{ ap-south-1 }}"
count: 1 # default
count_tag:
Name: Prod-Instance
instance_tags:
Name: Prod-Instance
vpc_subnet_id: subnet-00efd068
assign_public_ip: yes
delegate_to: localhost