add string to end of line ansible

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 :

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

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 :

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