Ansible中的block

361次阅读
没有评论

共计 625 个字符,预计需要花费 2 分钟才能阅读完成。

Ansible中的block

每次再操作节点进行系统的一些软件包更新时,由于存在ubuntu和centos系统,所以需要对系统判断来使用包管理器,每当后续有些操作需要就要写如下内容,繁琐。。。

when: ansible_os_family == 'RedHat'

正好最近浏览到ansible可以将任务合成为一个任务组,对组进行判断即可满足我的需求

---
- hosts: all
  tasks:
    #Install and configure Apache on RHEL/CentOS hosts. 
    - block:
        - yum: name=httpd state=present
        - template: src=httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf 
        - service: name=httpd state=started enabled=yes
      when: ansible_os_family == 'RedHat'
      become: yes

    #Install and configure Apache on Debian/Ubuntu hosts. 
    - block:
        - apt: name=apache2 state=present
        - template: src=httpd.conf.j2 dest=/etc/apache2/apache2.conf 
        - service: name=apache2 state=started enabled=yes
      when: ansible_os_family == 'Debian' 
      become: yes

正文完
 
xadocker
版权声明:本站原创文章,由 xadocker 2020-02-29发表,共计625字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)