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 }}"

 

posted @ 2020-04-03 18:11  Vincen_shen  阅读(1723)  评论(0编辑  收藏  举报