Using Ansible to check for a custom program to be installed

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!

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
  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

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.