Use of playbook in ansible

一、playbook

A playbook is written in YAML language similar to a shell script. It is a playbook for the configuration, deployment, and management of ansible. The extension of the playbook is usually .yml.
Basic use of playbook

命令	功能
-u	用于ssh所连接的用户名
-k	ssh登录认证的密码
-s	sudo获取root用户权限
-U	sudo到对应用户
-K	sudo用户密码
-T	ssh连接超时,默认是10秒
-C	在加上该命令后,进行playbook执行任务时不会真正执行,而是进行模拟执行,判断剧本是否有语法错误
-i	指定hosts文件路径
–list-hosts	显示会有哪些主机执行该playbook文件,而不是实际进行playbook执行
–list-tasks	列出该playbook中会执行的task
-v	在执行任务时显示详细的执行过程,-vv、-vvv可以得到更加详细的执行过程
–limit	指定执行命令的主机
–list-tags	列出命令的tag
–syntax-check	选择language

Two, YAML

yaml (full name: YAML Ain't Markup Language): is a format used to express data sequences. The format of
yaml:

  YAML的开头以”—“为开头,以”…“作为结尾(结尾可省略)
  YAML的结构使用空格
  YAML中的数组使用”-“进行表示
  YAML中的键值使用”:“进行表示
  YAML编辑时,同一个层级缩进必须对齐
  一个name中只能包含一个task
  YAML对缩进要求十分
  严格,如使用tab需要在~/.vimrc进行设定
  playbook中的核心元素:
  hosts:任务的目标主机
  name:对内容进行说明
  tasks:定义具体任务

vim setting skills

Setting file: vim ~/.vimrc
autocmd FileType yaml setlocal ai ts=2 sw=2 et
parameter function

ai(auto indent)	自动退格对齐
ts(tabstop=2)	tab长度设定为两空格
sw(shiftwidth=2)	缩进长度为2
et(expandtab)	将tab键变为空格

Guess you like

Origin blog.csdn.net/qq_42958401/article/details/108638807