Ansible(十)小项目的一些细节性问题

一    对于下载的roles

出于安全原因,下载的代码需要仔细,研读每一行代码,不能直接在生产环境中应用

二   单个角色

---
- hosts: webservers
  roles:
    - apache

二    多个角色

---
- hosts: all
  tasks:
    - import_role:
        name: apache
      when: ansible_hostname in groups['webservers']
    - import_role:
        name: haproxy
      when: ansible_hostname in groups['lb']

# 引入的方式-->import_role,涉及判断(when)
- hosts: all
  tasks:
  - import_role:
      name: apache
    when: ansible_hostname in groups['webservers']
  - import_role:
      name: haproxy
    when: ansible_hostname in groups['lb']
  # 涉及主和备份
  - import_role:
      name: keepalived
    vars:
      STATE: MASTER
      VRID: 100
      PRIORITY: 100
    when: ansible_hostname == "server1"
  - import_role:
      name: keepalived
    vars:
      STATE: BACKUP
      VRID: 100
      PRIORITY: 50
    when: ansible_hostname == "server4"

# 变量的方式!

 

你可能感兴趣的:(Ansible)