ansible 变量定义

ansible变量定义有三种方式:剧本定义,文本定义,register接收定义

1.在playbook中定义

[root@ansbile ~]# cat test1.yml
- hosts: all
  gather_facts: no
  vars:
    test1: yang
  tasks:
    - file: path=/test/{{test1}} state=touch

2.在文本中定义引入

[root@ansbil ~]# cat test2.yml
- hosts: zk
  gather_facts: no
  vars_files:
      - var.yaml
  tasks:
  - name: echo date
    file: path=/test/{{test2}} state=directory

[root@ansbil ~]# cat var.yaml
test2: yang

3.接收上个play的值并定义为变量

[root@ansbile ~]# cat test3.yml
- hosts: zk
  gather_facts: no
  tasks:
    - shell: echo "test"
      register: test3
    
    - file: path=/test/{{test3.stdout}} state=touch

你可能感兴趣的:(ansible)