Satellite 6 deployment using extra vars on the Ansible Tower callback integration.

Solution In Progress - Updated -

Environment

  • Satellite 6.x
  • Red Hat Ansible Automation Platform 1.2
  • Ansible Tower 3.8.4

Issue

  • When using the Ansible Tower Callback to apply ansible changes, Satellite does not input extra vars on the Ansible Job.

Resolution

  • The workaround available is to clone the following templates according to the changes below.

    1) The first step is to clone the following Provisioning Templates, and append '_extra_vars' to the template names:

    • ansible_provisioning_callback -> ansible_provisioning_callback_extra_vars
    • ansible_tower_callback_script -> ansible_tower_callback_script_extra_vars
    • ansible_tower_callback_service -> ansible_tower_callback_service_extra_vars

    NOTE: The following changes require the '_extra_vars' term appended to the cloned template names.

    2) After cloning, the following changes must be applied to the new templates.

    - ansible_provisioning_callback_extra_vars

    13 <% if has_systemd -%>
    14 <%= save_to_file('/etc/systemd/system/ansible-callback.service',
    15                 snippet('ansible_tower_callback_service_extra_vars')) %> <============== Change the snippet template hostname.
    16 # Runs during first boot, removes itself
    17 systemctl enable ansible-callback
    18 <% else -%>
    19 # Assume systemd is not available
    20 <%= save_to_file('/root/ansible_provisioning_call.sh', snippet('ansible_tower_callback_script_extra_vars')) %> <============== Change the snippet template hostname.
    21 (chmod +x /root/ansible_provisioning_call.sh; crontab -u root -l 2>/dev/null; echo "@reboot /root/ansible_provisioning_call.sh" ) | crontab -u root -
    22 <% end -%>
    23 <% end -%>
    

    - ansible_tower_callback_script_extra_vars

    Replace the line below:

    10 /usr/bin/curl -v -k -s --data "host_config_key=<%= host_param('ansible_host_config_key') %>" https://<%= 
    host_param('ansible_tower_fqdn') %>/api/v2/job_templates/<%= host_param('ansible_job_template_id') %>/callback/
    

    With the following content:

    10 <% if host_param('ansible_extra_vars') -%>
    11 /usr/bin/curl -v -k -s -H 'Content-Type: application/json' --data '{"host_config_key":"<%= 
    host_param('ansible_host_config_key') %>", "extra_vars": <%=host_param('ansible_extra_vars') %>}' https://<%= 
    host_param('ansible_tower_fqdn') %>/api/v2/job_templates/<%= host_param('ansible_job_template_id') %>/callback/
    12 <% else -%>
    13 /usr/bin/curl -v -k -s --data "host_config_key=<%= host_param('ansible_host_config_key') %>" https://<%= 
    host_param('ansible_tower_fqdn') %>/api/v2/job_templates/<%= host_param('ansible_job_template_id') %>/callback/
    14 <% end -%>
    

    - ansible_tower_callback_service_extra_vars

    Replace the line below:

    14 ExecStart=/usr/bin/curl -k -s --data "host_config_key=<%= host_param('ansible_host_config_key') -%>" 
    https://<%= host_param('ansible_tower_fqdn') -%>/api/v2/job_templates/<%= host_param('ansible_job_template_id') -%>/callback/
    

    With the following content:

    14 <% if host_param('ansible_extra_vars') -%>
    15 ExecStart=/usr/bin/curl -k -s -H 'Content-Type: application/json' --data '{"host_config_key":"<%= 
    host_param('ansible_host_config_key') %>", "extra_vars": <%=host_param('ansible_extra_vars') %>}' https://<%= 
    host_param('ansible_tower_fqdn') %>/api/v2/job_templates/<%= host_param('ansible_job_template_id') %>/callback/
    16 <% else -%>
    17 ExecStart=/usr/bin/curl -k -s --data "host_config_key=<%= host_param('ansible_host_config_key') -%>" 
    https://<%= host_param('ansible_tower_fqdn') -%>/api/v2/job_templates/<%= host_param('ansible_job_template_id') -%>/callback/
    18 <% end -%>
    

    3) Once the change is applied, the additional parameter 'ansible_extra_vars' can be used on Satellite as a JSON template to input extra variables, as the following example shows.

    Host Parameters

    Name Type Value Actions
    ansible_extra_vars string {"var1": "bar", "var2": "world"}

    NOTE: The type must always be string.

    4) We need to check which is the kickstart template and finish template that are being used during the deployment and change it to use the new *_extra_vars snippet.

    You can find a host's templates by clicking the Resolve button on the Operating System tab when creating a host.

    The default template is Kickstart default; if you are using the default, this is the template that needs to be cloned and changed as the following lines.

    313 <% end -%>
    314
    315 <%= snippet('ansible_provisioning_callback_extra_vars') %> <====== Change the snippet called during the provisining template.
    316 
    317 <%= snippet 'efibootmgr_netboot' %>
    

    Also, this template needs to be associated with the operating system that is used during the deployment on the Association tab of the cloned template.

    In addition, the Finish template must be cloned, which ​by default is Kickstart default finish, and changed according to the following lines.

    78 <% if host_param_true?('ansible_tower_provisioning') -%>
    79 <%= save_to_file('/root/ansible_provisioning_call.sh', snippet('ansible_tower_callback_script_extra_vars')) %> <====== Change the snippet called during the provisioning.
    80 /root/ansible_provisioning_call.sh
    81 <% end -%>
    

    NOTE: Repeat the association process for this template as well.

    Once those two files have been changed and associated to the target Operating System, they need to be set as default for the Operating System that is being deployed. In order to do this, navigate the Satellite WebUI and go to:

    Hosts > Operating System > Select the Operating System (RHEL 7.9/RHEL 8.5/...) > Templates > Change the 'Finish template' and 'Provisioning template' for the respective one.
    

    5) Check if the 'PROMPT ON LAUNCH' check box is checked on the 'Extra variables' section on the Job Template used during the deployment.

    After that, the deployment should be complete with success, calling the Ansible Tower Callback API to start the Job Template using the extra variables defined on the host/hostgroup parameters.

Root Cause

  • Satellite 6 templates do not support extra variabless on the callback API. We have raised the bugzilla to address it.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments