我们正在构建Ansible手册,以在OVM基础架构中配置VM。该构建将克隆基于“ os ”变量的Windows或Linux映像,该变量通过外部变量文件传递给剧本。
ansible-playbook -i inventory.yml create_vm.yml -e @variables.yml
两个图片(Windows和Linux)都具有Ansible的固定IP地址(192.168.100.100)
我们正在寻找一种基于“ os ”变量动态选择 ansible_connection 类型(ssh或winrm)的方法,我已经在group_vars / staging_machines / vars中尝试过.yml:
ansible_connection: |
{% if os == 'Microsoft Windows Server 2016' or os == 'Microsoft Windows Server 2012' -%}winrm{% else -%}ssh{% endif -%}
但得到:fatal: [192.168.100.100]: FAILED! => {"msg": "the connection plugin 'ssh\n' was not found"}
inventory.yml是:
staging_machines:
hosts:
192.168.100.100: