I'm using geerlingguy's NTP role to set up NTP client software on a collection of hosts. I'd like to point this play at a hostgroup and have Ansible figure out on the fly whether or not each machine is a VM (an important thing to note here is that all of our VMs are running on KVM hypervisors). If the host is a VM, ntp_tinker_panic
should be set to true
. Otherwise, it should be set to false
. Here's the play I wrote:
- name: Set up NTP or chronyd on Linux hosts
hosts: ntp
tasks:
- name: Print the value of ntp_tinker_panic
debug:
var: ntp_tinker_panic
- name: Ensure time sync software is installed and configured
include_role:
name: geerlingguy.ntp
vars:
ntp_enabled: true
ntp_manage_config: true
ntp_timezone: America/New_York
ntp_servers:
- "time.google.com"
ntp_tinker_panic: "{{ ansible_facts['ansible_product_name'] == 'KVM' }}"
tags:
- ntp
However, even though the play executes without errors, the debug message states that ntp_tinker_panic
is not defined:
TASK [Print the value of ntp_tinker_panic] *****************************************************************************
ok: [hostname] => {
"ntp_tinker_panic": "VARIABLE IS NOT DEFINED!"
}
Is there a way for me to set the value of that variable on a per-host basis as the play is running instead of defining separate hostgroups for VMs and physical hosts?
question from:
https://stackoverflow.com/questions/65834101/how-can-i-set-the-value-of-a-variable-being-passed-to-a-role-based-on-ansible-fa 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…