10 changed files with 120 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||
[defaults] |
|||
jinja2_extensions = jinja2.ext.do |
|||
retry_files_enabled = False |
|||
@ -0,0 +1,30 @@ |
|||
|
|||
- name: Variables loaded dynamically are available everywhere in the playbook |
|||
gather_facts: no |
|||
hosts: localhost |
|||
tasks: |
|||
- include_vars: extra.yaml |
|||
roles: |
|||
- my-vars |
|||
post_tasks: |
|||
- debug: |
|||
var: extra |
|||
- debug: |
|||
var: extra_role |
|||
- assert: |
|||
that: |
|||
- extra is defined |
|||
- extra_role is defined |
|||
|
|||
- name: Even in another playbook ! |
|||
gather_facts: no |
|||
hosts: localhost |
|||
tasks: |
|||
- debug: |
|||
var: extra |
|||
- debug: |
|||
var: extra_role |
|||
- assert: |
|||
that: |
|||
- extra is defined |
|||
- extra_role is defined |
|||
@ -0,0 +1,4 @@ |
|||
--- |
|||
|
|||
- name: Include extra variables dynamically |
|||
include_vars: extra.yaml |
|||
@ -0,0 +1,3 @@ |
|||
--- |
|||
|
|||
extra_role: "I'm also there !" |
|||
@ -0,0 +1,2 @@ |
|||
--- |
|||
extra: "Yes, I'm there !" |
|||
@ -0,0 +1,34 @@ |
|||
--- |
|||
|
|||
- name: The selectattr filter can be used to filter a list, based on a criteria |
|||
gather_facts: no |
|||
hosts: localhost |
|||
vars: |
|||
input: |
|||
- id: 2555418101286 |
|||
system_name: hits |
|||
- id: 2555418119094 |
|||
system_name: Say_Hello |
|||
- id: 2555418119095 |
|||
system_name: Say_Goodbye |
|||
tasks: |
|||
- block: |
|||
- debug: |
|||
var: output |
|||
- assert: |
|||
that: |
|||
- output|length == 1 |
|||
- (output|first).system_name == 'Say_Hello' |
|||
vars: |
|||
output: "{{ input|selectattr('id', 'equalto', id)|list }}" |
|||
id: 2555418119094 |
|||
- block: |
|||
- debug: |
|||
var: output |
|||
- assert: |
|||
that: |
|||
- output|length == 1 |
|||
- (output|first).id == 2555418119094 |
|||
vars: |
|||
output: "{{ input|selectattr('system_name', 'equalto', system_name)|list }}" |
|||
system_name: Say_Hello |
|||
@ -0,0 +1,25 @@ |
|||
--- |
|||
|
|||
- name: 'Set Theory Filters: union operates on set of structured objects' |
|||
gather_facts: no |
|||
hosts: localhost |
|||
tasks: |
|||
- block: |
|||
- debug: |
|||
var: output |
|||
- assert: |
|||
that: |
|||
- output|length == 3 |
|||
vars: |
|||
output: "{{ input1|union(input2) }}" |
|||
input1: |
|||
- id: 1 |
|||
name: john |
|||
- id: 3 |
|||
name: smith |
|||
input2: |
|||
- id: 1 |
|||
name: john |
|||
- id: 2 |
|||
name: jane |
|||
|
|||
@ -0,0 +1 @@ |
|||
{{ input|default("KO") }}{{ input_template|default("KO") }}OK |
|||
@ -0,0 +1,2 @@ |
|||
{%- set input_template = "OK" -%} |
|||
{{ lookup('template', 'sub-template.j2') }} |
|||
@ -0,0 +1,16 @@ |
|||
--- |
|||
|
|||
- name: 'Variable in templates: a template can use a variable from task or playbook but not from an outter template' |
|||
gather_facts: no |
|||
hosts: localhost |
|||
vars: |
|||
input: 'OK' |
|||
tasks: |
|||
- block: |
|||
- debug: |
|||
var: output |
|||
- assert: |
|||
that: |
|||
- output == "OKKOOK" |
|||
vars: |
|||
output: "{{ lookup('template', 'template.j2') }}" |
|||
Loading…
Reference in new issue