logo

NJP

CPG - Calling Ansible Job as Day2 Operation

Import · May 11, 2022 · article

image a. Register Node

i. Registers the newly provisioned node with Ansible on the given Inventory and HostGroup

ii. Creates Host Credential at Ansible Tower.

b. Execute Job Template

i. Executes an Ansible Job template on the provisioned VM. Eg:- Apache, Tomcat etc..,

4. Configure Application Profile to select the Ansible Job Template.

image

---------------------------------------

Runtime

1. Deploy a Catalog Item with a simple VM.

2. Resolve NodeAddress and NodeCredentials

image

Expression to resolve NodeCredentials

$(Stack.items[Virtual Server].node_reference_credential[sn_cmp_vm_node_mgmt_creds:node].attribute[cred_id])

Mandatory Step needed by Ansible to create an Host credential at Ansible Tower

1. Create or use an existing record in sn_cmp_node_credential

image

2. Create an association between Node Credentials and the Node in sn_cmp_vm_node_mgmt_creds. Ansible will be picking these node credentials [username and password/private-key] to create host credential

image

3. Click on the Virtual Server and Select the Day2 operation. [Virtual Machine Store Extension Interface - Execute Job Template]

image

Send Extra Vars to Ansible Tower

image

Use ConfigurationOverrides attribute in order to override Extra Variables on Ansible Job Template.

[

[{ "name": "attribute", "value": "aws_zone" }, { "name": "value", "value": "${parameter.Location}" }],

[{ "name": "attribute", "value": "contact_email" }, { "name": "value", "value": "[email protected]" }],

[{ "name": "attribute", "value": "port" }, { "name": "value", "value": "9090" }]

]

Troubleshoot

2 operations run at the Ansible Tower [Register Node, Execute Job Template].

1. Inputs to Register Node

image

2. Inputs to Execute Job Template

image

3. Connection between Ansible and MID Server

curl -u : -k https:///api/v2/organizations/

4. Credential association exists between Server and Credentials in sn_cmp_vm_node_mgmt_creds.

Note:

Register Node should run only once for a node. Execute Job Template can run multiple times on the same node to deploy a different Job template.

Labels:

View original source

https://www.servicenow.com/community/itom-blog/cpg-calling-ansible-job-as-day2-operation/ba-p/2270969