# Can this be concatinated?  Made more graceful?

**URL:** <https://forum.ansible.com/t/can-this-be-concatinated-made-more-graceful/25796>\
**Category:** Ansible Project\
**Created:** [October 20, 2017, 9:24pm UTC](https://forum.ansible.com/t/can-this-be-concatinated-made-more-graceful/25796 "2017-10-20T21:24:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [October 20, 2017, 9:24pm UTC](https://forum.ansible.com/t/can-this-be-concatinated-made-more-graceful/25796/1 "2017-10-20T21:24:02Z")

</div>

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

`

---

<div class="post-metadata">

**Author:** ![wildfan](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@wildfan](https://forum.ansible.com/u/wildfan)\
**Post date:** [October 21, 2017, 4:18pm UTC](https://forum.ansible.com/t/can-this-be-concatinated-made-more-graceful/25796/2 "2017-10-21T16:18:05Z")

</div>

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

`

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

```

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

```

`
