Ansible condition when string not matching

后端 未结 2 768
情书的邮戳
情书的邮戳 2021-01-31 15:53

I am trying to write an Ansible playbook that only compiles Nginx if it\'s not already present and at the current version. However it compiles every time which is undesirable.

相关标签:
2条回答
  • 2021-01-31 16:10

    Since var is a json string you can parse it to json and access it's keys.

    set_fact:
      var_json: "{{ var.stdout|from_json }}"
    

    Then access the json and get the value you want.

    when: var_json.nginxVersion.stdout == 'nginx version: nginx/1.8.0'
    

    checkout this link: https://gist.github.com/justinhennessy/28e82c2ec05f9081786a

    0 讨论(0)
  • 2021-01-31 16:24

    Try:

    when: nginxVersion.stdout != 'nginx version: nginx/1.8.0'
    

    or

    when: '"nginx version: nginx/1.8.0" not in nginxVersion.stdout'
    
    0 讨论(0)
提交回复
热议问题