If it were my code, i'd probably instead of checking for the nagios user 
existing, check that the package is installed ( ie rpm -q and register 
output), or do a stat on the /usr/local/nagios/etc directory and copy the 
file if is exists..  its not a whole lot compact or cleaner than what you 
have, but it at least wont fail if for some reason you have a nagios user 
on a box, but dont have the directory structure in place such as your 
current code.  In your example, if the nagios user is there, it assumes 
that the /usr/local/nagios/etc path exists as a landing pad for your 
nrpe.cfg file.

Since i dont know what is you install nrpe via a package manager, below is 
an example using stat to check for the etc directory 

- name: Checking for existing nagios etc directory
  stat: 
    path: "/usr/local/nagios/etc"

  register: nag_dir

- name: Copy nrpe.cfg to client
  copy: 
    src: /etc/ansible/masterfiles/nagios/nrpe.cfg
    dest: /usr/local/nagios/etc/
    owner: nagios
    group: nagios
    mode: 0644
  when: nag_dir.isdir is defined and nag_dir.isdir
  notify: reload xinetd



On Friday, October 20, 2017 at 4:24:02 PM UTC-5, John Harmon wrote:
>
> I have the following, which works, but it just got me wondering if this 
> can be concatenated or be written in a more graceful way? By that, I don't 
> mean *getent: database=passwd, key=nagios*
>
> - name:  Check for nagios installation
>   getent:
>     database: passwd
>     key: nagios
>   ignore_errors: yes
>   register: nagios_user
>
> - name:  Copy nrpe.cfg to clients when installed
>   copy:
>     src: /etc/ansible/masterfiles/nagios/nrpe.cfg
>     dest: /usr/local/nagios/etc/
>     owner: nagios
>     group: nagios
>     mode: 0644
>     force: yes
>   when: nagios_user|succeeded
>   notify: reload xinetd
>
>
>

-- 
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/8048a745-ea64-4977-830b-8a066a428c57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to