Ansible用脚本管理主机
Last updated
Last updated
---
- hosts: web
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: Write the configuration file
template: src=templates/httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf
notify:
- restart apache
- name: Write the default index.html file
template: src=templates/index.html.j2 dest=/var/www/html/index.html
- name: ensure apache is running
service: name=httpd state=started
handlers:
- name: restart apache
service: name=httpd state=restarted[
{
"hosts": "web",
"vars": {
"http_port": 80,
"max_clients": 200
},
"remote_user": "root",
"tasks": [
{
"name": "ensure apache is at the latest version",
"yum": "pkg=httpd state=latest"
},
{
"name": "Write the configuration file",
"template": "src=templates/httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf",
"notify": [
"restart apache"
]
},
{
"name": "Write the default index.html file",
"template": "src=templates/index.html.j2 dest=/var/www/html/index.html"
},
{
"name": "ensure apache is running",
"service": "name=httpd state=started"
}
],
"handlers": [
{
"name": "restart apache",
"service": "name=httpd state=restarted"
}
]
}
]