可以使用 vars 指定变量,也可以使用 var_files
指定变量文件
---
- name: ansible playbook
hosts: all
remote_user: root
become: yes
vars:
user_name: 'test'
var_files:
tasks:
- name: 添加用户
user:
name: '{{user_name}}'
state: present
groups: wheel,sudo
append: yes
tags:
- user
使用:
ansible-playbook play.yml -t user --extra-vars 'user_name=test1'