Advertisement

ansible系列15 实践学习playbook配置与循环结构

阅读量:

Ansible平台内置了丰富的功能模块,支持编写playbook脚本,并且具备条件判断与循环控制等高级功能,使得绝大多数脚本能够实现的操作均可通过Ansible完成。其中,条件判断的实现依赖于when关键字,而循环结构则通过with_items进行定义。接下来将通过具体示例来展示这些功能的使用方式。

条件判断playbook实例

复制代码
    [root@host31 ~]# cat hello.playbook
    - hosts: host31
      gather_facts: true
      tasks:
    - name:  say redhat hello task
      shell: echo "RedHat"  `date` by `hostname` >> /tmp/hello.log
      when:  ansible_os_family ==  "RedHat"
    - name:  say other linux hello task
      shell: echo "Not RedHat"  `date` by `hostname` >> /tmp/hello.log
      when:  ansible_os_family !=  "RedHat"
    [root@host31 ~]#

全部评论 (0)

还没有任何评论哟~