Jinja2 filter list using string contains test

后端 未结 4 1647
遥遥无期
遥遥无期 2021-02-20 06:01

I\'m trying to filter a list in ansible in Jinja2 when the elements contain a string, but the Jinja documentation doesn\'t seem clear enough for me to figure it out.

Thi

4条回答
  •  忘了有多久
    2021-02-20 06:21

    I ended up writing a python script to do it, because I couldn't get ansible or ancient-jinja2 to make the cut.

    Ansible tasks:

    - name: gather run info
      command: "{{role_path}}/files/print_results.py {{script_results.stdout_lines}}"
      register: script_print_results
      delegate_to: 127.0.0.1
      run_once: true
    
    - name: display run info
      debug:
        var: script_print_results.stdout_lines
      delegate_to: 127.0.0.1
      run_once: true
    

    Python script:

    for result_line in sys.argv[1:]:
        if "running script:" in result_line:
            print result_line[1:-1]
    

提交回复
热议问题