ansible-playbook

Posted c040

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible-playbook相关的知识,希望对你有一定的参考价值。

简单例子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的主要内容,如果未能解决你的问题,请参考以下文章

[Docker][ansible-playbook]3 持续集成环境初探

Ansible-playbook自动部署MySQL主从

在命令“ansible-playbook”中加密用户私钥文件

ansible-playbook调试

ansible-playbook

ansible-playbook 变量(vars)