Skip to content

Host Variables

TF edited this page Feb 16, 2023 · 6 revisions

About

Open-AudIT uses fields (which are meant to be "custom fields") and attributes (which are a special kind of fields) to identify device objects.
That is important as both are handled differently by the Open-AudIT api and so within this collection.

This collection will read and write both types of objects while they are managed slightly different.

Note: sedi.openaudit.set manages atm only the devices collection while this might get extended in the future to support others as well.

This page describes Ansible host (i.e. Open-AudIT device) variables only. For group variables check out Group variables.

For automatically mapped internal Open-AudIT fields see Auto-mapped Open-AudIT Variables.

For an Ansible-like documentation see of sedi.openaudit.set here

Custom fields (Fields -> Create)

Available as Ansible host variables yes
Open-AudIT configuration https://<server>/open-audit/index.php/fields
Ansible configuration inventory host file, eg. hosts.openaudit.yml

You can add as many custom fields you like and as soon as you configure them in oa_fieldsTranslate and add values at a device they will appear as a host variable in Ansible. These have the highest precedence and can be overwritten only by extra-vars set on the CLI call directly.

Usually (and this is the recommended approach) you will create a custom field in Open-AudIT and then do the <variable-name>: id mapping in your local hosts.openaudit.yml inventory file:

oa_fieldsTranslate:
    foo: 7
    myvar_for_ansible: 13
    my_other_var: 21

Means: you have created 3 custom fields in Open-AudIT (named it somehow - the name there does NOT matter) and you got the ids 7, 13 and 21 from Open-AudIT (Manage -> Fields -> field details -> field: ID). Then you added them to your hosts.openaudit.yml inventory file within the oa_fieldsTranslate dictionary. Now you can edit your device(s) in Open-AudIT and set the values you like for every of these custom fields and they will automagically appear in Ansible as host variables! That's it.

See the playbook example how these could then be changed by sedi.openaudit.set.

Open-AudIT fields / objects

Available as Ansible host variables no
Open-AudIT configuration https://<server>/open-audit/index.php/attributes
https://<server>/open-audit/index.php/devices
Ansible configuration within a task using sedi.openaudit.set

Internal Open-AudIT fields / objects and Attributes https://<server>/open-audit/index.php/attributes and basically any object you can find in a device's view. That means all except those which are shown in the "Custom fields" menu.

sedi.openaudit.set allows to set all these internal device fields, too. The main question here is how to find the proper field name for it:

Two ways to achieve this can be used:

  1. (Recommended) Specify an invalid fieldname, e.g. this_field_doesnt_exist: foo within your sedi.openaudit.set task and let it run. The output will show all available internal / Open-AudIT field names. Task example:
    - name: "Show all internal Open-AudIT fields"
      connection: local
      become: no
      sedi.openaudit.set:
        api_server: my.openauditserver.local
        api_protocol: https
        username: "{{ vault_api_server_user }}"
        password: "{{ vault_api_server_password }}"
        collection: devices
        attributes:
            - fqdn: "{{ inventory_hostname }}"
              fields:
                my_invalidfield: foo
  1. (only if 1 does not work for you) In Open-AudIT open the browsers developer console (network tab). change the value of interest and check the payload of the post. You will find there "meta" -> "received data" -> "attributes" {<fieldname> : <value>}. Important is that all these internal Open-AudIT fields (i.e. not custom field) must be prefixed with oa.. so status becomes oa.status etc. Following the recommended step 1 above will show them correctly already so its always recommended to do it that way (besides its much easier).

See the playbook example how these could then be changed by sedi.openaudit.set.

Special / Magic

Sometimes you might need/want to have just 1 single field which holds all your variables in once. Here comes a special "magic" variable into play: free_form_vars. The format is slightly different from the Group-Variables ones as there is no need to add ;; which marks the beginning of variable definitions (which is needed in the Classic or location based group variables).

Variable Name Meaning Example value
free_form_vars A magic custom field which you need to create once in Open-AudIT and in the inventory mapping. It can hold all key=value pairs (semicolon separated) you like in 1 line.
free_form_vars is not activated automatically, it must be added to oa_fieldsTranslate if you want to make use of it
foo=bar;cow=moo;and=so_on

Final note: free_form_vars is a very special one. You might better avoid using it as it can become messy when it grows but well, it's here if you need it ;) It is usually always better using single custom fields instead of this one.