1. The role of external file variables
The variable file can realize the centralized management of variables, making the management of variables more convenient and efficient. In the deployment of a large cluster architecture, the relationship between each machine can be flexibly defined, which is convenient for improving deployment compatibility.
Two, call the external variable playbook file
---
- hosts: test
vars_files:
- vars.yml #外部变量文件与ping.yaml文件相同目录
remote_user: "{{user}}" #调用外部变量
become: yes
tasks:
- name: "判断该主机的存活状态"
ping:
Three, vars.yml variable file
[root@Ansible playbook]# cat vars.yml
user: cedar
Four, verification results
[root@Ansible playbook]# ls
ping.yaml test.yaml vars.yml yum_zookeeper.yaml
[root@Ansible playbook]# ansible-playbook ping.yaml
PLAY [test] *****************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************
ok: [10.3.153.8]
TASK [判断该主机的存活状态] ***********************************************************************************************************************************************
ok: [10.3.153.8]
PLAY RECAP ******************************************************************************************************************************************************
10.3.153.8 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0