Inventory变量(在主机清单配置文件中定义变量)
[root@contorl ansible]# vim hosts
[test]
node1 myvar1=“hello the world” myvar2=“content” #在node1主机中定义了两个变量
[proxy]
node2
[webserver]
node[3:4]
[database]
node5
[cluster:children]
webserver
database
[webserver:vars]
yourname=“jacob” #在webserver主机组所有主机定义变量
[root@contorl ansible]# vim inventory_var.yaml
---
- hosts: test
tasks:
- name: create a file with var.
shell: echo "{{myvar1}}" > /tmp/"{{myvar2}}"
- hosts: webserver
tasks:
- name: create a user with var
user:
name: "{{yourname}}"
[root@contorl ansible]# ansible-playbook inventory_var.yaml
[root@node1 ~]# ls /tmp
[root@node1 ~]# cat /tmp/content
[root@node3 ~]# id jocab