码迷,mamicode.com
首页 > 其他好文 > 详细

ansible-playbook(2)

时间:2019-02-09 22:45:04      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:roo   hand   image   load   enc   mic   ati   handlers   res   

简单例子1: vars定义变量

  • - hosts: all
    remote_user: root
    vars:
    - package: nginx
    - service: nginx
      tasks:
    - name: install nginx package
      yum: name={{ package }} state=latest
    - name: install configuration file for httpd
      copy: src=/etc/nginx/nginx.conf dest=/etc/nginx/nginx.conf
      notify:
          - restart nginx
    ?
    - name: start httpd service
    service: enabled=true name={{ service }} state=started
    handlers:
    - name: restart nginx
    service: name={{ package }} state=restarted

     

条件测试: when条件测试

- hosts: all
remote_user: root
vars:
- username: user2
tasks:
- name: create {{ username  }} user
  user: name={{ username }}
  when: ansible_distribution == "CentOS"

 

迭代

技术图片

 

技术图片

ansible-playbook(2)

标签:roo   hand   image   load   enc   mic   ati   handlers   res   

原文地址:https://www.cnblogs.com/c040/p/10358084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!