Hi Sebastiaan,

Thanks for sharing. It's helpful..

Kevin

On Friday, July 5, 2013 at 1:55:27 AM UTC-7, Sebastiaan Pouyet wrote:
>
> Thanks for your help Michael and Mark, I appreciate it!
> In addition to Mark's example, another way of checking the existence of a 
> path is with the stat module which was added in 1.3:
>
> ---
> - name: Check if path exists
>   stat: path=/etc/monit/conf.d
>   register: check_path
>
> - name: It exists
>   debug: msg='Yay, the path exists!'
>   when: check_path.stat.exists
>
> - name: It doesn't exist
>   debug: msg="Boohoo, the path doesn't exist..."
>   when: check_path.stat.exists == false
>
>
> On Thursday, July 4, 2013 1:14:47 AM UTC+2, Mark Mandel wrote:
>>
>> if you need an example, I did it this way here:
>>
>> https://github.com/markmandel/dotfiles/blob/master/provision/roles/core/tasks/_oh_my_zsh.yml#L4
>>
>> For my local oh-my-zsh provisioning.
>>
>> (Short version)
>>
>> - name: See if zsh is installed
>>
>>
>>   shell: "[ -d ~/.oh-my-zsh ] && echo 'Found' || echo ''"
>>
>>   register: zsh_installed
>> - name: install oh my zsh
>>
>>
>>
>>   shell: wget 
>> https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | 
>> zsh
>>
>>   when: (not zsh_installed.stdout)
>>
>>
>> On Wed, Jul 3, 2013 at 11:57 PM, Michael DeHaan <[email protected]> 
>> wrote:
>>
>>> Sure thing.
>>>
>>> You probably want to use the register module to save the result of a 
>>> test and act upon it.   What command you want to execute is pretty wide 
>>> open, maybe it's rpm -qa, etc.
>>>
>>>    - shell: ...
>>>      register: some_result
>>>
>>> Then you might do:
>>>  
>>>    - copy: ...
>>>      when: some_result.rc == 0
>>>
>>>
>>> In 1.3, there's also a 'stat' module you can use which returns lots of 
>>> useful attributes and works really well with register.
>>>
>>> Should you want to use facts instead to write a "monit installed fact", 
>>> you could do that too ... there shouldn't be any need to use facter, as you 
>>> could write your own ansible facts and just call the module.
>>>
>>> There is also the new "facts.d" feature in Ansible 1.3 (not yet 
>>> documented as it's the development version), where you can drop a JSON file 
>>> or executable script that returns JSON into /etc/ansible/facts.d/*.fact
>>>
>>>
>>>
>>>
>>> On Wed, Jul 3, 2013 at 8:02 AM, Sebastiaan Pouyet <[email protected]> 
>>> wrote:
>>>
>>>> Hi all,
>>>>
>>>> I've searched the group and the ansible documentation, but haven't been 
>>>> able to find a clear answer.
>>>>
>>>> I want to conditionally upload a monit config file in a nginx playbook, 
>>>> but only when the monnit conf directory is present.
>>>>
>>>> tasks: 
>>>>   - name: "add monit nginx config" 
>>>>     copy: src=nginx.monit dest=/etc/monit/conf.d owner=root group=root 
>>>> mode=0700 
>>>>     when: ???
>>>>
>>>> The when condition should return True if the 
>>>> directory /etc/monit/conf.d/ exists. 
>>>>
>>>> How can I achieve this? Is the an expression I can use, or should I set 
>>>> a "monit_installed" fact in the monit role, or use facter?
>>>> Also, is there a difference between only_if and when?
>>>>
>>>>
>>>> Cheers and one zillion gallactic kudos for developing Ansible!
>>>>
>>>> Sebastiaan
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Ansible Project" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>  
>>>>  
>>>>
>>>
>>>
>>>
>>> -- 
>>> Michael DeHaan <[email protected]>
>>> CTO, AnsibleWorks, Inc.
>>> http://www.ansibleworks.com/
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Ansible Project" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>
>>
>> -- 
>> E: [email protected]
>> T: http://www.twitter.com/neurotic
>> W: www.compoundtheory.com
>>
>> 2 Devs from Down Under Podcast
>> http://www.2ddu.com/
>>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e9db0d21-09a7-4ad2-ad28-1c6028cc8222%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to