0

我有一个 ansible 任务,它获得所有弹性搜索角色

- name: Get all roles
  shell: curl -u elastic:123456789 "192.168.2.13:9200/_security/role"
  register: roles

并且我想执行下面的任务,前提是角色.stdout 变量包含单词 Uzbekistan

- name: register role (if doesn't exist)
  shell: curl -u elastic:123456789 "192.168.2.12:9200"
  when: roles.stdout =="Uzbekistan"

那么我该怎么做呢?

4

1 回答 1

1

有很多方法可以做到这一点

使用search

- name: register role (if doesn't exist)
  shell: curl -u elastic:123456789 "192.168.2.12:9200"
  when: roles.stdout is search('Uzbekistan')

使用in

- name: register role (if doesn't exist)
  shell: curl -u elastic:123456789 "192.168.2.12:9200"
  when: "'Uzbekistan' in roles.stdout"

使用find

- name: register role (if doesn't exist)
  shell: curl -u elastic:123456789 "192.168.2.12:9200"
  when: roles.stdout.find('Uzbekistan')
于 2020-11-16T14:42:56.450 回答