Difference between revisions of "Ansible Playbooks"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
+ | # Order of vars | ||
+ | - inventory vars | ||
+ | - vars_files in playbook (outside of tasks) | ||
+ | - vars in tasks after os fact discovery | ||
+ | |||
Set host connection to winrm on windows without ssh | Set host connection to winrm on windows without ssh | ||
Revision as of 01:01, 19 November 2021
Order of vars
- inventory vars
- vars_files in playbook (outside of tasks)
- vars in tasks after os fact discovery
Set host connection to winrm on windows without ssh
And change auth creds via include vars by group name var
You could use template env vars with jinja template too
https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html
https://docs.ansible.com/ansible/latest/cli/ansible-playbook.html
https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html
ansible-playbook -i 127.0.0.1 ansible-playbook site.yml --limit datacenter2 -f 10
Using if or lookup from env in jinja vars
--- - name: -Test- hosts: local vars: my_group_var: False # my_group_var: True tasks: - name: Prepare vars file from template. template: src=/tmp/vars.yaml.j2 dest=/tmp/vars.yaml - name: Include vars include_vars: "/tmp/vars.yaml"
The content of example jinja template /tmp/vars.yaml.j2 is:
{% if my_group_var %} test: var1: value var2: value {% else %} test: var1: other_value var2: other_value {% endif %}