# Using Ansible to check for a custom program to be installed

**URL:** <https://forum.ansible.com/t/using-ansible-to-check-for-a-custom-program-to-be-installed/16885>\
**Category:** Ansible Project\
**Created:** [November 25, 2014, 9:24pm UTC](https://forum.ansible.com/t/using-ansible-to-check-for-a-custom-program-to-be-installed/16885 "2014-11-25T21:24:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_Grebin](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@Adrian\_Grebin](https://forum.ansible.com/u/Adrian_Grebin)\
**Post date:** [November 25, 2014, 9:24pm UTC](https://forum.ansible.com/t/using-ansible-to-check-for-a-custom-program-to-be-installed/16885/1 "2014-11-25T21:24:42Z")

</div>

Hi guys, i am new to Ansible, and trying to make good use of it on our environment.

We’re running a tool that is called Opsware (that is some kind of ansible as well…) that should be running it’s agent on each node.  
I want to automate the installation of the agent via ansible and trying to write a role for it, not sure if i am going to need to write a module, i think it wont be needed, but would appreciate your feedback.

I wrote a simple task:

- name: make sure opsware-agent is runnning  
service: name=opsware-agent state=running pattern=“/opt/opsware/agent/bin/python /opt/opsware/agent/pylibs/shadowbot/daemonbot.pyc --conf /etc/opt/opsware/agent/agent.args”

This runs so far when the agent is installed, if it is not running it will restart it.  
I wonder if the ‘pattern’ parameter is a good idea to check for the process to be running if the agent is actually not installed, since it is not installed via any software package system (yum/apt) so my idea to check if it was installed is to check if the service is running and if it fails to check the service status, then it is not installed.

I am unsure from here how to trigger the install if the ‘pattern’ fails…

I would appreciate your input/feedback with this issue.

Thanks!

---

<div class="post-metadata">

**Author:** ![jorginator74](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@jorginator74](https://forum.ansible.com/u/jorginator74)\
**Post date:** [November 26, 2014, 10:25pm UTC](https://forum.ansible.com/t/using-ansible-to-check-for-a-custom-program-to-be-installed/16885/2 "2014-11-26T22:25:53Z")

</div>

Hi

> Hi guys, i am new to Ansible, and trying to make good use of it on our  
> environment.
> 
> We're running a tool that is called Opsware (that is some kind of ansible as  
> well...) that should be running it's agent on each node.  
> I want to automate the installation of the agent via ansible and trying to  
> write a role for it, not sure if i am going to need to write a module, i think  
> it wont be needed, but would appreciate your feedback.
> 
> I wrote a simple task:
> 
> - name: make sure opsware-agent is runnning  
> &nbsp;&nbsp;service: name=opsware-agent state=running pattern="/opt/opsware/agent/bin/  
> python /opt/opsware/agent/pylibs/shadowbot/daemonbot.pyc --conf /etc/opt/  
> opsware/agent/agent.args"
> 
> This runs so far when the agent is installed, if it is not running it will  
> restart it.

That sounds wrong. If it is already running, it should be left alone,  
as you have "state=running".

IIRC Ansible relies on the init script being able to return a status -  
and many 3rd party init scripts fail to do so... The "pattern" part  
in ansible is an attempt at working around this, but the init script  
really should be fixed... (Perhaps you can use ansible to installed a  
fixed version first?)

What does "/etc/init.d/optsware-agent status" say? (and more  
importantly: What exit code does it give?)

> I wonder if the 'pattern' parameter is a good idea to check for the process to  
> be running if the agent is actually not installed, since it is not installed  
> via any software package system (yum/apt) so my idea to check if it was  
> installed is to check if the service is running and if it fails to check the  
> service status, then it is not installed.

Well - hopefully nothing will match the pattern if the right daemon is  
not installed...

> I am unsure from here how to trigger the install if the 'pattern'  
> fails...

Can you check for the presense of one of the files installed by  
opsware-agent instead? E.g. /usr/sbin/opsware-agent or similar?

Hope this helps

---

<div class="post-metadata">

**Author:** ![Mehul\_Ved](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mehul\_Ved](https://forum.ansible.com/u/Mehul_Ved)\
**Post date:** [November 27, 2014, 12:51pm UTC](https://forum.ansible.com/t/using-ansible-to-check-for-a-custom-program-to-be-installed/16885/3 "2014-11-27T12:51:52Z")

</div>

Would it not be a good idea to use stat to first check if the files  
are present? If not, that means it isn't installed and wouldn't  
trigger any error.  
Then do the check whether service is running.
