I want to print var1
and var2
in one Ansible task. I have this working YAML.
- debug:
var: "{{ item }}"
with_items:
- var1
- var2
I wonder whether is possible to do it without using with_items
nor msg
parameter.
I want to print var1
and var2
in one Ansible task. I have this working YAML.
- debug:
var: "{{ item }}"
with_items:
- var1
- var2
I wonder whether is possible to do it without using with_items
nor msg
parameter.
I find this to be very handy:
- name: Display variables
ansible.builtin.debug:
msg:
- "x: {{ x }}"
- "y: {{ y }}"
You can definitely have multiple variables in a debug message, as long as it is a valid YAML.
For example, the task
- debug:
msg:
var1: "{{ var1 }}"
var2: "{{ var2 }}"
vars:
var1: foo
var2: bar
Yields
ok: [localhost] =>
msg:
var1: foo
var2: bar
And if you really don't want a message, drop the two variables in a dictionary:
- debug:
var: to_debug
vars:
to_debug:
var1: "{{ var1 }}"
var2: "{{ var2 }}"
var1: foo
var2: bar
Yields
ok: [localhost] =>
to_debug:
var1: foo
var2: bar
I find this to be very handy:
- name: Display variables
ansible.builtin.debug:
msg:
- "x: {{ x }}"
- "y: {{ y }}"
You can use the vars
option in the debug
task to print the values of multiple variables in one go. Here's an example:
- debug:
vars:
var1: "{{ var1 }}"
var2: "{{ var2 }}"
© 2022 - 2025 — McMap. All rights reserved.
fatal: [localhost]: FAILED! => msg: 'Invalid options for debug: vars'
. Neither the docudebug
module – Print statements during execution nor the Action Plugin sourceplugins/action/debug.py
show such parameter and syntax. Are you mixing it up with Using variables? – Tails