CH06
CH06

Reputation: 167

How to show specific number of lines in Ansible debug task

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

Answers (1)

β.εηοιτ.βε
β.εηοιτ.βε

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

Related Questions