Adding host variables

Hello All,

I have a requirement to add variable to thousands of hosts. Can anyone let me know what will be the quickest way to achieve this?

Thanks,

Depends on how you configured this hosts, director or plain config files or using ansible etc.

Hi @anon66228339

I have configured hosts through director import jobs.

Thanks,

Then its easy, modify your import/sync job to add the variables you need :slight_smile:
And reimport / sync everything.

But the problem is I have to add variables only to specific number of hosts. Say if we have 2000 host in that i may have to add variables only to hunderd host and not all… And those 100 host are distinct only with host name currently.

First off, hide such things in a host template. Depending on the ruleset defined, you can either import that template into synced host objects, nor not. That requires 2+ rules though.

1 Like

Hello @dnsmichi : Currently i cannot import the template into synced host objects. Is it possible to apply host template to hostgroups using wildcard(checked in director but getting error for wildcard)? or anyother way?

Thanks for your time. Much appreciated…

No, a host template cannot be imported into a hostgroup, their attributes do not match. A soft link for syncing and grouping inside the Director doesn’t exist to my knowledge.

Why?

Cheers,
Michael

Unsure on defining the perfect ruleset for my requirement. Is it possible to define a rule that can be applied only to hosts on certain hostgroups.

Apologies in advance if my question is wrong.

Thanks

Depends on the import source. If that’s SQL for instance, the WHERE clause can be modified as such.

1 Like

We solved a similar problem recently for services looping icingacli director on the command line, with the “–json” option. I can provide an example if desired.

If all the variables are to get the same value, templates are definitely the way to go, though, I agree. Set up a template, and then use icingacli director in a loop to “–import” this template for your list of hosts.

2 Likes

Yep, please, always :heart:

The following example sets host variables, after all. Misremembered that. Here we go (shell loop extract):

IFS='|'
while read HNAME ADDR PROF USNMP WP CP
    do 
        :   # some variable validation here
        sudo icingacli director host set $HNAME  --address $ADDR --display_name $HNAME  --imports "$PROF" && \
        sudo icingacli director host set --json '{"vars._override_servicevars": {"Interface-Table": { "submode": " '$USNMP'", "wp": "'$WP'", "cp": "'$CP'"}} }'
        : 
    done < /tmp/hdata.txt

I’ve included 2 icingacli director call-ups to show that the --json option can’t be mixed with other options; it will “nullify” them and only the JSON stuff will be done. The USNMP shell variable can be either empty or contain the string “–unixsnmp”.

2 Likes

Thanks much for your time, highly appreciated… Will this host variable still exists even after next host import sync?

I don’t have much experiences with imports or Fileshipping. I just wanted to show you how you can set up variables via the command line (without directly “editing” any DB). The variables settings in the example are actually service variables for a service “Interface-Table” of a service set associated with the host. You can also use single variable definitions by using single --vars.xyz options, where xyz ist the (new) variable name.