Monday, February 5, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...