ansible register with loop debug print not working

后端 未结 1 489
傲寒
傲寒 2021-01-24 03:28

i have a simple playbook that is supposed to display my services status. and i want to view the output from the machine to see if the status is active or not. so i used a debug

相关标签:
1条回答
  • 2021-01-24 03:59

    For modules, including debug, called in a loop (ie with_items), the value of item at each iteration will be shown. I don't know of a way to turn this off. If you want you reduce your output you can try switching to using the msg parameter to the debug module which takes a jinja templated string. You could do something like this obviously adjusting the regex to match systemctl output.

    - name: show values
      debug: msg="{{ item.stdout_lines | replace_regex('^(.*).service.*Active: (.*).$', \\\1 \\\2) }}"
      with_items: out.results
    

    If you don't want to use the replace_regex function you can consider writing your own filter plugin to format the data the way you like it.

    In general ansible playbooks aren't a great place to display status information gathered through register vars, facts, etc. The playbook output is more geared toward task status.

    0 讨论(0)
提交回复
热议问题