# add string to end of line ansible

**URL:** <https://forum.ansible.com/t/add-string-to-end-of-line-ansible/29102>\
**Category:** Ansible Project\
**Created:** [November 23, 2018, 12:21pm UTC](https://forum.ansible.com/t/add-string-to-end-of-line-ansible/29102 "2018-11-23T12:21:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylan\_Osef](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@Dylan\_Osef](https://forum.ansible.com/u/Dylan_Osef)\
**Post date:** [November 23, 2018, 12:21pm UTC](https://forum.ansible.com/t/add-string-to-end-of-line-ansible/29102/1 "2018-11-23T12:21:02Z")

</div>

I want to create a role to do a dynamic update of my Nagios configuration when I create a new VM.

So to do that, i already created a role which add a host definition at the end of my servers.cfg Nagios file, it looks like :

```auto
- name: Add {{ Host_Name }} in /etc/naemon/conf.d/hosts/servers.cfg
  blockinfile:
    dest: /etc/naemon/conf.d/hosts/servers.cfg
    block: |
      define host {
        host_name {{ Host_Name }}
        alias {{ Host_Name }}.uem.lan
        address {{ Host_IP }}
        use modele_host,host-pnp
      }
    marker: ""
    backup: yes

```

It works well.

So now I would like to be able to add my “`{{ Host_Name }}`” server directly at the end of lines of checks files.

Exemple : This is a check to monitore `/data` partition :

```auto
define service {
  service_description /data partition
  host_name myserv1,myserv2,myserv3,myserv4,myserv5
  use srv-pnp,modele_service_disk_linux_snmp
  check_command check_snmp_storage!uem_snmp!/data$!90!95
}

```

And I would to add my “`{{ Host_Name }}`” like that :

```auto
define service {
  service_description /data partition
  host_name myserv1,myserv2,myserv3,myserv4,myserv5,{{ Host_Name }}
  use srv-pnp,modele_service_disk_linux_snmp
  check_command check_snmp_storage!uem_snmp!/data$!90!95
}

```

Would anyone have a solution?

Thx 🙂
