I suggest you add a task, before your win_service task that installs the
service if it is not yet installed. Depending on what the service is, you
might be able to use win_package to install it. If it is already
installed, there is not much to loose by running the win_package task a
second time, as it will only install if not installed.
When provisioning, I like to write playbooks that drag the machine into the
state that I want it in rather than trying to write playbooks that have to
handle lots of different possiblities that might exist on the different
machines.
Hope this helps,
Jon
On Wednesday, 16 March 2016 11:46:50 UTC, ishan jain wrote:
>
> I am trying to provision windows server 2012 R2 machine with ansible and
> for that i need to gather some custom facts about the running services. I
> tried getting the information via the win_service module like this:
>
> ---
> - hosts: windows
> tasks:
> - name: check services
> win_service:
> name: test1
> register: result
> ignore_errors: yes
>
> - debug: msg="{{result}}"
>
> - debug: msg="service is running"
> when: result.state == 'running'
>
>
> This works fine if the service exists but in case the service does not
> exist, i get ugly looking failed message in the win_service task and as
> there is no common member name in the registered variable 'result', i am
> not sure how to first check if the service really exist and then proceed to
> do something further. Is there a better way to check if service exists and
> if yes, what is its state ?
>
--
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/18b8640a-b0d3-4c10-b6ea-a89900267cf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.