Ansible使用介绍

72课时
1.9K学过
8分

课程评价 (0)

请对课程作出评价:
0/300

学员评价

暂无精选评价
3分钟

09 tasks

作用:任务列表

格式:module: arguments

注意:shell和command模块后面跟命令,而非key=value

检查playbook:

ansible-playbook -C file.yml

运行playbook的方式:

ansible-playbook …options

options:

–check 只检测可能会发生的改变,但不真正的操作

–list-hosts 列出运行任务的主机

–limit 主机列表 只针对主机列表中的主机执行

-v,-vv,-vvv 显示详细过程

一个最简单的Playbook需包含的基础组件有host、remote_user、tasks

示例1:

vim http.yml

– hosts: websrvs

remote_user: root

tasks:

– name: create new file

file: name=/data/newfile state=touch

– name: create new file

user: name=test2 system=yes shell=/sbin/nologin

– name: install package

yum: name=httpd

– name: copy index

copy: src=/var/www/html/index.html dest=/var/www/html/

– name: start service

service: name=httpd state=started enabled=yes