User Tools

Site Tools


api:export:externalsystemansible

ExportAPI: Destination Ansible

This destination creates an dynamic inventory for the configuration management tool Ansible. The exporter walks through all CMDB objects that are configured as export source and creates Ansible groups. The output is written to stdout.

As ansible has some specifications when executing scripts for dynamic inventory, you need a little wrapper script, which comes with yourCMDB, to use this exporter. You can find the wrapper ansibleExport.sh in the <yourCMDB-dir>/contrib directory. To use it, please set the following variables in the script to fit your needs:

EXPORTER_TASK=<name of the yourCMDB exporter task>
EXPORTER_BIN=<path to the exporter.php in yourCMDB/scripts>

Configuration

short information
class name ExternalSystemAnsible
needed variableshostname
hostvar_*
group_*

destination parameters

no destination parameters are available at the moment

variables

namerequireddescriptionexample
hostnamerequiredhostname or IP that Ansible uses for connecting to the host test.example.com
group_*requiredAnsible group membership. group_webservers ⇒ true
hostvar_*optionalhost variables that should be given to Ansible hostvar_snmpread ⇒ public

For each CMDB object the export variable hostname has to be set which is used by Ansible to connect to a CMDB object. Hosts are organized in Ansible groups. For adding a CMDB object to a specific group, the group_* variables are used. The variable name is group_groupname and the value is true, if the CMDB object should be a member of the group. Example:

variablename: group_webserver
value of the variable for object: true
behavior: the object is part of the Ansible group webserver.

You can set host variables for Ansible using the hostvar_* variables. The variable name is hostvar_varname, which means, you can access the value by using the name varname in Ansible.

Examples

example of export task configuration:

<task name="ansible-example">
<sources>
	<source objecttype="server" status="A" />
</sources>
<destination class="ExternalSystemAnsible">
	<parameter key="output" value="stdout" />
</destination>
<variables>
	<variable name="hostname">
		<value objecttype="server" fieldname="management-ip" />
	</variable>
	<variable name="hostvar_hostname">
		<value objecttype="server" fieldname="hostname" />
	</variable>
	<variable name="hostvar_ip">
		<value objecttype="server" fieldname="management-ip" />
	</variable>
	<variable name="group_defaultpackage">
		<value objecttype="server" fieldname="configtask-defaultpackage" />
	</variable>
	<variable name="group_backupagent">
		<value objecttype="server" fieldname="configtask-backupagent" />
	</variable>
	<variable name="group_fail2ban">
		<value objecttype="server" fieldname="configtask-fail2ban" />
	</variable>
</variables>
</task>
api/export/externalsystemansible.txt · Last modified: 2017/07/24 11:43 (external edit)