Skip to content

Instantly share code, notes, and snippets.

@ifd3f
Last active May 1, 2024 19:20
Show Gist options
  • Save ifd3f/476a42a693a760b8c51e166bb4eeb21f to your computer and use it in GitHub Desktop.
Save ifd3f/476a42a693a760b8c51e166bb4eeb21f to your computer and use it in GitHub Desktop.
sorta-syntactic-macros in ansible
- name: ansible has syntactic macros ehe :3
hosts: ::1
connection: local
tasks:
- name: Run a shell command and register its output to foo_result
ansible.builtin.shell: echo myfoo first
register: foo_result
- name: Syntactically generate some tasks
copy:
dest: intermediate.generated.yml
content: "{{ tasks | to_json }}"
vars:
tasks:
- name: Print something silly
ansible.builtin.debug:
msg: "test uwu >:3 foo_result was templated in as: {{ foo_result.stdout }}"
- name: Set foo_result to something else to test scoping
ansible.builtin.shell: echo myfoo second
register: foo_result
- name: Execute the generated tasks
ansible.builtin.include_tasks: intermediate.generated.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment