YAML语言
编写一个简单剧本,使被控主机安装httpd服务,并提供index.html,test.html文档,最后启动服务
---
- hosts websrvs
#表示当前剧本的操作对象是
remote_user: root
tasks:
#任务
- name: Install Httpd
#任务描述
yum: name=httpd
#执行操作
- name: Index File Copy
copy: src=files/index.html dest=/var/www/html/
- name: Test Page Copy
copy: src=files/test.html dest=/var/www/html/
- name: Httpd Service
service: name=httpd state=started enabled=yes
到此该简单剧本编写完成,当前的文件树如下:
httpd.yml
files
index.html
test.html
运行该剧本
检查语法错误
~]# ansible-playbook -C httpd.yml
执行该剧本
~]# ansible-playbook httpd.yml
测试服务是否正常启动
~]# curl http://172.16.10.10
正常情况下会返回index.html
中的内容