Ansible strip white space

|▌冷眼眸甩不掉的悲伤 提交于 2020-04-11 03:57:39

问题


When I try to run some commands on nxos devices, the output has a white space at the end. I have to compare the output to an existing variable list. The whitespace at the end is causing the comparison to go false. How to make use of .strip() function in a list of strings?

- name: Current TACACS server host before
    nxos_command:
      commands:
        - sh run | include 'tacacs-server host'
register: runconfserafter

- debug:
    var: runconfserafter

The output of this comes up like this:

"stdout_lines": [
        [
            "tacacs-server host 1.1.1.1 key 7 \"HelloWorld\" ",
            "tacacs-server host 2.2.2.2 key 7 \"HelloWorld\""
        ],
     ]

When I compare this line with my desired variables, I can't get it matched because of the white space on the first line at the end.


回答1:


To apply a function to list elements use map filter. To strip whitespace use trim filter.

"{{ runconfserafter.stdout_lines | map('trim') | list }}"


来源:https://stackoverflow.com/questions/51015315/ansible-strip-white-space

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!