ansible04 脚本管理主机

来源:互联网 发布:哥特鸟嘴面具 知乎 编辑:程序博客网 时间:2024/05/16 09:18

为了避免重复的输入命令,ansible提供了脚本功能。playbook,使用的yaml格式。文件后缀yml或者yaml

ansible-playbook deploy.yml

---
- hosts: 10.0.0.5
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: name=httpd state=latest


  - name: write default index.html
    template: src=/data/index.html dest=/var/www/html/index.html


  - name: ensure apache is running
    service: name=httpd state=started


ansible-playbook deploy.yml 


hosts:某主机的ip,或者主机组名,或者关键字all。

remote_user 以某个用户身份执行

vars:变量

tasks: playbook的核心,定义顺序执行的动作action。每个action调用一个ansible模块