ansible变量定义

原文链接: http://www.cnblogs.com/ray-mmss/p/10176015.html

一./etc/ansible/hosts

[webServers]
192.168.2.100 http_port=8080
192.168.2.200 http_port=8009

[web]
web1
web2

[db]
db1
db2

[app:children]
web
db

二./etc/ansible/hosts

[webServers]
192.168.2.100 
192.168.2.200 
[webServers:vars]
name=nginx

三.playbook中定义

- hosts: test
  remote_user: root
  vars:
    - path: /usr/local/nginx/sbin/nginx
    - var2: value2

四.命令行指定

[root@L ansible]# ansible-playbook -e 'http_port=80 name=nginx' test.yaml

五.独立文件

[root@L ansible]# vim vars.yaml
var1: httpd
var2: vsftpd
---
- hosts: test
  remote_user: root
  vars_files:
    vars.yaml

  tasks:
    - name: install httpd
      yum : name={{ var1 }}

 六.嵌套子变量

---
- hosts: test
  remote_user: root


  tasks:
    - name: create user
      user: name={{ item.name }} group={{ item.group }}
       with_items:
            - { name: 'user1' , group: 'group1}
            - { name: 'user1' , group: 'group1}        

 

转载于:https://www.cnblogs.com/ray-mmss/p/10176015.html

你可能感兴趣的:(ansible变量定义)