我想同步数据3台主机拉一台主机我做了这个
- name: Pull data from master-0 to 3nodes
synchronize:
src: /data/backups/
dest: /root/test/
mode: pull
delegate_to: "{{ inventory_hostname in groups['new_percona'] }}"
when: '"master-0" in inventory_hostname'但它是失败的。
ERROR! the field 'delegate_to' has an invalid type (<class 'bool'>), and could not be converted to a string type.如何在delegate_to上使用inventory_hostname组变量?
发布于 2021-05-27 21:58:35
delegate_to需要字符串类型,例如:
delegate_to: my.domain.com
# or
delegate_to: 10.20.230.4 对于您提供的代码片段,如下所示:
"{{ inventory_hostname in groups['new_percona'] }}" # --> return a boolean这就是为什么你会有“错误”。
对于您的问题,您可以查找过滤出的主机('when‘使用情况),如下所示:
{{ hostvars['abc.example.com']['your_var'] }}
# or
hostvars[inventory_hostname].ansible_ssh_host参考:
https://stackoverflow.com/questions/67719910
复制相似问题