Reputation: 167
How to show only the first five lines of the hostvars
variable in Ansible?
- name: "Show Ansible hostvars var"
debug:
msg: "{{ hostvars }}" # How to stop after 5 showed lines?
Upvotes: 1
Views: 64
Reputation: 39314
One way could be to translate the YAML dictionary into a string, split it on line feed, apply a slice, then, join it back into a single string.
For example:
- debug:
msg: "{{ (hostvars | to_nice_yaml | split('\n'))[:5] | join('\n') }}"
Upvotes: 2