Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an "apply_for" service with "vars += config" #210

Open
MarcusCaepio opened this issue May 23, 2023 · 9 comments
Open

Create an "apply_for" service with "vars += config" #210

MarcusCaepio opened this issue May 23, 2023 · 9 comments

Comments

@MarcusCaepio
Copy link

Hi all,
i am freshly looking at this module which looks very promising. I can do things via the director API, which I cannot do in the director WebUI, e.g. defining a dictionary in a host object. So first of all, thanks a lot to all contributors!
I am currently trying to create a service apply rule, which is written in DSL like this:

apply Service "tcp: " for ( tcp => config in host.vars.tcp ) {
	import "generic-service"
	check_command = "tcp"
	vars += config
	assign where host.vars.tcp
}

But the apply_for parameter does not create the "tcp =>" and the "vars += config" part ( or I am doing it wrong).
The ansible role of icinga supports it in their module ( https://github.com/Icinga/ansible-collection-icinga/blob/main/doc/role-icinga2/objects.md#service-apply-for ). Anyway, there are using the DSL ( I guess) and I want to have everythinbg visible and maybe editable in the director beside of ansible, as I don't want to mix places for configs. Could anybody give me a hand here?

Thanks and cheers,
Marcus

@rndmh3ro
Copy link
Collaborator

Hey @MarcusCaepio,

the service_apply module has the argument apply_for.

Evaluates the apply for rule for all objects with the custom attribute specified. For example selecting “host.vars.custom_attr” will generate “for (config in host.vars.array_var)” where “config” will be accessible through “$config$”. Note - only custom variables of type “Array” are eligible.

Is this what you're looking for?

@MarcusCaepio
Copy link
Author

Hey @rndmh3ro
exactly it is, what I am looking for and I already tried it with this (should have mentioned this in my first post). Problem here is, that I could not get it configured to have the "tcp =>" before config in and also the "vars += config" line could not be created.

@rndmh3ro
Copy link
Collaborator

Can you provide us with some example code that's not working?

@MarcusCaepio
Copy link
Author

Given the example in my first post, I tried:

  • setting the apply_for parameter in various ways, but I cannot get the part tcp => before the config part:
  • setting the vars: parameter in various ways to get vars += config ,e.g.:
    vars: += config or
vars:
  += config

all result in errors
So basically, if the module supports the functionality to build the config exactly like in my DSL example from the first post, it would be awesome. I don't know, if the module can parse the configs like the icinga role:
https://github.com/Icinga/ansible-collection-icinga/blob/main/doc/role-icinga2/objects.md#advanced-syntax

@rndmh3ro
Copy link
Collaborator

Okay, can you please create a service_apply object in the director-frontend? Then show via the API what's stored in the director. You can either do this via curl (or similar):

> curl -s  -H "Accept: application/json" https://your-icinga-instance/director/services/applyrules

or with Ansible:

- hosts: localhost
  gather_facts: false
  tasks:
    - name: Query a service apply rule in icinga
      t_systems_mms.icinga_director.icinga_service_apply_info:
        force_basic_auth: true
        url: "https://your-icinga-instance"
        url_username: ""
        url_password: ""
        query: "NAME_OF_APPLY_RULE"

@MarcusCaepio
Copy link
Author

There's the point: The director-frontend currently does not allow to create such an "apply-for" service.
As same as the director-frontend currently does not allow to create dictionaries in hosts like:

vars.tcp["5666"] = {
  tcp_port = "5665"
}

But for the host dictionaries, it is possible with your module and I can easily create them ( although I just notified that these dictionaries are not shown in the dirtector-frontend too.... ).

vars:
  tcp:
    "5665":
        tcp_port: "5665"

So I hoped, I can create services like this too :)

@rndmh3ro
Copy link
Collaborator

If you find a way to create this object via the director (frontend or API), then please share it with us, so we can see if and how it is possible to do it with Ansible.

@MarcusCaepio
Copy link
Author

I'll try my best. But as I am currently testing on a docker-compose playground, I am struggling on this issue ^^
Icinga/icingaweb2-module-director#2642

@rndmh3ro
Copy link
Collaborator

Your struggle is my struggle. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants