-s, --snippet Show playbook snippet for specified module(s)
-v, --verbose verbose mode (-vvv for more, -vvvv to enable
connection debugging)
--version show program's version number and exit
ansible-doc -l 列出所有ansible的模板;
ansible-doc +模块名称 查看ansible模块的用法,例如:
ansible-doc template #查看template模块的用法
2.学会使用roles
我的习惯性写法,无论定义多小的playbook都会创建这几个文件夹:roles,common,+自定义的role;然后再在每个role下面写ymal文件。格式如下,也推荐大家使用这种排版。
roles可以实现“代码复用”。只是把任务给分离出去了。只要在playbook文件中调用此role就可执行这些任务,常用的task一般放到common下。例如下面的playbook:
root@localhost:/home/xujpxm/ansible/vspc_snmp# cat sysctlconf.yml
# This playbook is used to replace sysctl.conf file
# note that Ansible facts and vars like ansible_os_family can be used
# directly in conditionals without double curly braces
这里引用ansible_os_family需要注意一点是,ansible开启gather_facts参数,默认是开启的。
9.ansible-lint
ansible-lint是对playbook的语法进行检查的一个工具。用法是ansible-lint playbook.yml
安装:
$ pip install ansible-lint 用法示例,监测语法错误:
$ ansible-lint setup_galera_cluster.yml
Syntax Error while loading YAML.
The error appears to have been in '/Users/junxian/script/ansible/ubuntu_galera_cluster/roles/galera_cluster_install/tasks/secure.yml': line 24, column 2, but may
be elsewhere in the file depending on the exact syntax problem.