每一个play都是一系列的task(任务),任务执行是按照顺序一次一个的执行的,每个任务的目的是调用一个模块,通过特定的参数,变量
模块是可以重复执行的,模块执行过程中只会变更需要变更的部分来达到目的状态,所以你可以重复执行某个模块
command 和shell模块会重复执行,如果是chmod这样的命令也是没有关系的
每一个task 都需要有一个name,这个name会在palybook执行的时候输出,如果没有提供name,输出的时候就会输出action的内容
下边是一个例子
task:
– name: make sure apache is running
service: name=httpd state=running
command 和shell是唯一的模块不用通过 key=value方式工作的:
tasks:
– name:disable selinux
command:/sbin/setenfore 0
command 和shell 模块在执行的时候我们需要知道是否执行成功:
tasks:
– name: run this command and ignore the result
shell:/usr/bin/somecommand || /bin/true或者
tasks:
– name: run this command and ignore the result
shell: /usr/bin/somecommand
ignore_errors:True
task中是允许换行的,例如:
tasks:
– name: Copy ansible inventory file to client
copy: src=/etc/ansible/hosts dest=/etc/ansible/hosts
owner=root group=root mode=0644
task中是可以使用变量的,前提是你在之前已经定义了变量
tasks:
– name:create a virtual host file for {{host}}
template: src=somefile.j2 dest=/etc/httpd/conf.d/{{host}}
欢迎转载,转载请注明出处:http://www.503error.com/
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021