Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 变量包含某个单词时可执行的运行任务_Linux_Ansible_Devops - Fatal编程技术网

Linux 变量包含某个单词时可执行的运行任务

Linux 变量包含某个单词时可执行的运行任务,linux,ansible,devops,Linux,Ansible,Devops,我有一个ansible任务,它拥有所有elasticsearch角色 - name: Get all roles shell: curl -u elastic:123456789 "192.168.2.13:9200/_security/role" register: roles 我只想在roles.stdout变量包含word时执行下面的任务 - name: register role (if doesn't exist) shell: curl -u ela

我有一个ansible任务,它拥有所有elasticsearch角色

- name: Get all roles
  shell: curl -u elastic:123456789 "192.168.2.13:9200/_security/role"
  register: roles
我只想在roles.stdout变量包含word时执行下面的任务

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

那么我该怎么做呢?

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

使用
搜索

-名称:注册角色(如果不存在)
外壳:卷曲-u形弹性:123456789“192.168.2.12:9200”
当:roles.stdout为搜索('乌兹别克斯坦')时

-名称:注册角色(如果不存在)
外壳:卷曲-u形弹性:123456789“192.168.2.12:9200”
当:“‘乌兹别克斯坦’在roles.stdout中”
使用
find

-名称:注册角色(如果不存在)
外壳:卷曲-u形弹性:123456789“192.168.2.12:9200”
时间:roles.stdout.find('乌兹别克斯坦')

角色是一个重要的角色。不要把它当作变量。Thanq Volodija!非常感谢。我会给你一道菜和一个新鲜的爆米花!