Using Ansible to check for a custom program to be installed

324 views
Skip to first unread message

Adrian Grebin

unread,
Nov 25, 2014, 4:24:43 PM11/25/14
to ansible...@googlegroups.com
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!
~                                                                                      

Karl E. Jorgensen

unread,
Nov 26, 2014, 5:26:07 PM11/26/14
to ansible...@googlegroups.com
Hi

On Tue, Nov 25, 2014 at 01:24:42PM -0800, Adrian Grebin wrote:
> 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.

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

--
Karl E. Jorgensen

Mehul Ved

unread,
Nov 27, 2014, 7:52:18 AM11/27/14
to ansible...@googlegroups.com
On Wed, Nov 26, 2014 at 2:54 AM, Adrian Grebin <adrian...@gmail.com> wrote:
> 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.

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.

--
With Regards,
Mehul Ved
Reply all
Reply to author
Forward
0 new messages