我使用ansible作为系统编排工具.首先,让我描述一下我最终的目标.
我想创建一个或两个剧本,从网上抓取solr,自行设置,然后根据某些配置启动索引.如果到目前为止听起来有任何疑问,请在这里阻止我.
现在,如果我不需要,我不想抓住solr tarball,所以我现在有一个看起来像这样的任务/游戏.
- stat: path="path to solr home/solr/bin/init script" register: solr_script - name: getting solr when: solr_script.stat.exists == False shell: mkdir -p "path to download dir" get_url: url="download url" dest= "path to download dir" shell: tar zxvf "path to download dir/tgz file" -C "path to solr home" shell: rm -rf "path to download dir" - name: start solr shell: "path to solr home/solr/bin/solr init script" start sudo: yes
我试图检查solr init脚本是否已经下载,然后再去抓取它.
当我按原样运行此脚本时,我收到错误,
multiple actions specified in task: 'shell' and 'getting solr'
这似乎是合理的,也许格式化是错误的?我试过这个
- name: getting solr when: solr_script.stat.exists == False shell: mkdir -p "path to download dir" get_url: url="download url" dest= "path to download dir" shell: tar zxvf "path to download dir/tgz file" -C "path to solr home" shell: rm -rf "path to download dir"
语法错误了.
在ansible文档页面上,我看到了一些信息.
Note that if you have several tasks that all share the same conditional statement, you can affix the conditional to a task include statement as below. All the tasks get evaluated, but the conditional is applied to each and every task:
这似乎正在达到我的需要.
但随后他们跟进了这个例子.
- include: tasks/sometasks.yml when: "'reticulating splines' in output"
我真的不明白"包含",而这个例子似乎并没有说明我想要的东西.所以,如果我的初始假设是正确的,这确实是我想要获得solr的方式,那么我将如何编写一个有条件地执行一组任务的ansible任务.
在Ansible 2.0中,它可能是这样的:
- block: - shell: mkdir -p "path to download dir" - get_url: url="download url" dest= "path to download dir" - shell: tar zxvf "path to download dir/tgz file" -C "path to solr home" - shell: rm -rf "path to download dir" when: solr_script.stat.exists == False
希望这会帮助你.