Monday, 5 February 2018

yaml - Ansible Jinja2 in vars.yml group_vars

We are building Ansible playbook to provision VMs in OVM infrastructure. The build will clone an Windows or Linux image based on "os" variable that passed to the playbook via external variables file.



ansible-playbook -i inventory.yml create_vm.yml -e @variables.yml


Both images (Windows and Linux) have fix IP address for Ansible (192.168.100.100)




We are looking for a way to dynamically chose ansible_connection type (ssh or winrm) based on the "os" variable, I have tried in group_vars/staging_machines/vars.yml:



ansible_connection: | 
{% if os == 'Microsoft Windows Server 2016' or os == 'Microsoft Windows Server 2012' -%}winrm{% else -%}ssh{% endif -%}


But getting: fatal: [192.168.100.100]: FAILED! => {"msg": "the connection plugin 'ssh\n' was not found"}



inventory.yml is:




staging_machines:
hosts:
192.168.100.100:

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...