playbook详解—YAML格式的文本

在playbook中有一些核心的指令

hosts:指明命令运行在哪个node之上 
remote_user:在远端的node之上以什么用户的身份运行命令 
var:给模板传递变量值 
tasks:指明需要执行的命令 
template:指明模板文件 
handler:指明句柄所在文件目录名 
Roles:指明需要运行的角色名

(一)检查playbook是否正确

ansible-playbook -- syntax-check first.yml

(二)预执行playbook

ansible-playbook --check first.yml

(三)查看执行命令的node节点的IP地址或主机名

ansible-playbook -- list-hosts first.yml
first.yml
 
- hosts: webservers
remote_user: root
tasks:
- name: install httpd
yum: name=httpd state=latest
- name: distribute config file
copy: src=config/httpd.conf dest=/etc/httpd/conf/httpd.conf
tags: redistibute
notify: restart httpd
- name: start httpd
service: name=httpd state=started enabled=yes
- name: check httpd started
shell: netstat -lntup | grep 80
 
 
handlers:
- name: restart httpd
service: name=httpd state=restarted enabled=yes

(四)使用vars定义变量

- hosts: dbservers
remote_user: root
vars:
- username: home
- groupname: uplooking
tasks:
- name: add group
group: name={{ groupname }}
- name: add user
user: name={{ username }} state=present

转载于:https://www.cnblogs.com/liu1026/p/7639720.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值