I am using ansible as a system orchestration tool. First of all, let me describe my eventual goal.
I want to create a playbook or two that will go grab solr from the web, set itself up, and then start an index based on some configuration. If any of this so far sounds suspect, please stop me here.
Now, I don't want to grab the solr tarball if I don't have to, so I've currently got a task/play that looks like this.
- 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
I attempting to check if the solr init script has already been downloaded before going and grabbing it.
When I ran this script as is, I get the error,
multiple actions specified in task: 'shell' and 'getting solr'
That seems reasonable-ish, maybe the formatting is wrong? I tried this
- 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"
Got a syntax error.
On the ansible documentation page, I see this bit of information.
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:
That seems to be getting to what I need.
But then they follow up with this example.
- include: tasks/sometasks.yml
when: "'reticulating splines' in output"
I don't really understand the "include", and the example doesn't seem to illustrate what I want. So, if my initial assumptions are correct and this is indeed how I would want to go about getting solr, how would I write up an ansible task that will conditionally execute a group of tasks.
Aucun commentaire:
Enregistrer un commentaire