Skip to content

Instantly share code, notes, and snippets.

@mz0
Last active February 5, 2019 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mz0/4462cb7bdae37881a21660c5703a0fd2 to your computer and use it in GitHub Desktop.
Save mz0/4462cb7bdae37881a21660c5703a0fd2 to your computer and use it in GitHub Desktop.
-- Icanhaz mai var, Ansible? -- Not after 2.8 of me!
- name: Return task result in a variable named in 'ret'
debug: msg="My first argument is {{ arg1 | default("undefined!") }}"
register: "{{ ret }}"
- hosts: localhost
gather_facts: no
vars:
var_a: "dynamic include AAA"
var_b: "dynamic include_tasks BBB"
var_c: "static import_tasks CCC"
tasks:
- name: Check ret0 before task include.
debug: msg="ret0 is {{ ret0 | default("undefined!") }}"
- name: You wouldn't see this 'name' in output (
include: inc1.yml
vars:
arg1: "{{ var_a }}"
ret: ret0
- name: Check returned var
debug: msg="ret0 is {{ ret0 | default("undefined!") }}"
- name: Run inc1.yml with 'include_tasks'.
include_tasks: inc1.yml
vars:
arg1: "{{ var_b }}"
ret: ret0
- name: Check returned var
debug: msg="ret0 is {{ ret0 | default("undefined!") }}"
- name: Neither would you see this 'name'!
import_tasks: inc1.yml
vars:
arg1: "{{ var_c }}"
ret: ret0
- name: Check returned var
debug: msg="ret0 is {{ ret0 | default("undefined!") }}"
@mz0
Copy link
Author

mz0 commented Feb 5, 2019

This is my version of a wonderful answer given 2017-05-23 18:43:28Z to a question "How can Ansible 'register' in a variable the result of included playbook?"

Works OK in Ansible 2.7.6 but not in 2.8.0dev0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment