Ansible Playbook 变量传递

1. 可以在命令行传递变量

 ansible-playbook -e "host=dev user=root" vars.yaml

---
- name: var test
  hosts: "{{ host }}"
  tasks:
    - name: var test
      debug:
        msg: "Hello {{ user }}"

 

2. 可以将变量写在inventory

 ansible-playbook -e "host=dev" vars.yaml

[all:vars]
user=root

[dev]
servera.lab.example.com
---
- name: var test
  hosts: "{{ host }}"
  tasks:
    - name: var test
      debug:
        msg: "Hello {{ user }}"

 

你可能感兴趣的:(Ansible Playbook 变量传递)