外部传入变量值
---
- hosts: testB
remote_user: root
tasks:
- name: "Passing Variables On The Command Line"
debug:
msg: "{{pass_var}}"
不给值会报错
只会输出被引用的变量值
---
- hosts: testB
remote_user: root
tasks:
- name: "Passing Variables On The Command Line"
debug:
msg: "{{num_var}}"
同时引用传入多个变量值
---
- hosts: testB
remote_user: root
tasks:
- name: "Passing Variables On The Command Line"
debug:
msg: "{{num_var,pass_var}}"
外部传入值的优先级大于内部定义
---
- hosts: testB
remote_user: root
vars:
pass_var: test
tasks:
- name: "Passing Variables On The Command Line"
debug:
msg: "{{pass_var}}"
命令行传入值
ansible testB -e "testdir=redhat" -m shell -a "echo {{testdir}}"
文件传入变量值
---
- hosts: testB
remote_user: root
tasks:
- name: "Passing Variables On The Command Line"
debug:
msg: "{{testvar}} {{numlist[2]}}"