Icinga / ansible-icinga2

Ansible Role for Icinga 2
Apache License 2.0
50 stars 23 forks source link

i2_custom_constants for ApiListner creates faulty config #42

Closed Nokius closed 4 years ago

Nokius commented 4 years ago

looks like the template creates a faulty configuration for the api feature.

the variables used as mentioned in the README

i2_custom_features:
  ApiListener:
    api: 
       accept_config: true
       accept_commands: true

The result ansible creates

# cat features-enabled/ApiListener.conf 
// Ansible managed

object ApiListener "api" {
   accept_config = "True"
accept_commands = "True"
}

syntax complain

# icinga2 daemon -C
[2020-01-28 16:14:53 +0100] information/cli: Icinga application loader (version: r2.11.2-1)
[2020-01-28 16:14:53 +0100] information/cli: Loading configuration file(s).
[2020-01-28 16:14:53 +0100] information/ConfigItem: Committing config item(s).
[2020-01-28 16:14:53 +0100] critical/config: Error: Error while evaluating expression: Can't convert 'True' to a floating point number.
Location: in /etc/icinga2/features-enabled/ApiListener.conf: 4:4-4:25
/etc/icinga2/features-enabled/ApiListener.conf(2): 
/etc/icinga2/features-enabled/ApiListener.conf(3): object ApiListener "api" {
/etc/icinga2/features-enabled/ApiListener.conf(4):    accept_config = "True"
                                                      ^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/features-enabled/ApiListener.conf(5): accept_commands = "True"
/etc/icinga2/features-enabled/ApiListener.conf(6): }

[2020-01-28 16:14:53 +0100] critical/config: 1 error
[2020-01-28 16:14:53 +0100] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.

Result expected is

cat features-enabled/ApiListener.conf 
// Ansible managed
object ApiListener "api" {
   accept_config = true
   accept_commands = true

Looks like the api follows a different syntax then the other features.

unfortunately my ansible skill is not enough to make PR. :(

Thanks for your feedback.

RossBarnie commented 4 years ago

Hi,

It's been a while since I've used this but can you try again with quotes around "true"? I think ansible/yaml treats true/false and yes/no as reserved words for Boolean values so will convert them to python-compatible "True" and "False".

If this fixes the issue it would helpful if you could provide a PR to fix the README.

On Tue, 28 Jan 2020, 15:24 Nokius, notifications@github.com wrote:

looks like the template https://github.com/Icinga/ansible-icinga2/blob/master/templates/feature-generic-template.conf.j2#L6 creates a faulty configuration for the api feature.

the variables used as mentioned in the README

i2_custom_features: ApiListener: api: accept_config: true accept_commands: true

The result ansible creates

cat features-enabled/ApiListener.conf

// Ansible managed

object ApiListener "api" { accept_config = "True" accept_commands = "True" }

syntax complain

icinga2 daemon -C

[2020-01-28 16:14:53 +0100] information/cli: Icinga application loader (version: r2.11.2-1) [2020-01-28 16:14:53 +0100] information/cli: Loading configuration file(s). [2020-01-28 16:14:53 +0100] information/ConfigItem: Committing config item(s). [2020-01-28 16:14:53 +0100] critical/config: Error: Error while evaluating expression: Can't convert 'True' to a floating point number. Location: in /etc/icinga2/features-enabled/ApiListener.conf: 4:4-4:25 /etc/icinga2/features-enabled/ApiListener.conf(2): /etc/icinga2/features-enabled/ApiListener.conf(3): object ApiListener "api" { /etc/icinga2/features-enabled/ApiListener.conf(4): accept_config = "True" ^^^^^^^^^^^^^^^^^^^^^^ /etc/icinga2/features-enabled/ApiListener.conf(5): accept_commands = "True" /etc/icinga2/features-enabled/ApiListener.conf(6): }

[2020-01-28 16:14:53 +0100] critical/config: 1 error [2020-01-28 16:14:53 +0100] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.

Result expected is

cat features-enabled/ApiListener.conf // Ansible managed object ApiListener "api" { accept_config = true accept_commands = true

Looks like the api follows a different syntax then the other features.

unfortunately my ansible skill is not enough to make PR. :(

Thanks for your feedback.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Icinga/ansible-icinga2/issues/42?email_source=notifications&email_token=AATSX4IHTPFWRKAHFIHYW4DRABEZJA5CNFSM4KMUJXNKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IJIGFTQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATSX4JVYCR4BPB42KSOG7LRABEZJANCNFSM4KMUJXNA .

Nokius commented 4 years ago

Hi @RossBarnie,

I tried it but I got quoted output too.

RossBarnie commented 4 years ago

There are a few suggestions on https://github.com/ansible/ansible/issues/11905:

Can you try these and let us know if any fix your issue?

Nokius commented 4 years ago

sorry FOSDEM weekend was in between,

vars:

  ApiListener:
    api:
      accept_command: !!str true
      accept_config: "{{ true | lower }}"

result is:

object ApiListener "api" {
   accept_command = "true"
accept_config = "true"
}

the remaining issue are the double quotes

[2020-02-03 17:56:59 +0100] critical/config: Error: Error while evaluating expression: Can't convert 'true' to a floating point number.
Location: in /etc/icinga2/features-enabled/ApiListener.conf: 4:4-4:27
/etc/icinga2/features-enabled/ApiListener.conf(2): 
/etc/icinga2/features-enabled/ApiListener.conf(3): object ApiListener "api" {
/etc/icinga2/features-enabled/ApiListener.conf(4):    accept_commands = "true"
                                                      ^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/features-enabled/ApiListener.conf(5): accept_config = "true"
/etc/icinga2/features-enabled/ApiListener.conf(6): }

[2020-02-03 17:56:59 +0100] critical/config: 1 error
RossBarnie commented 4 years ago

Looks like there is a bug here in that we do special-case False attributes but not True ones, see https://github.com/Icinga/ansible-icinga2/blob/master/templates/object_attributes.j2#L28.