hi all,
below is my playbook ia m trying to add some variable in extra_vars: argument and based on the condition but its giving error can some guide me how can we mention this like if string ‘oracle’ is there in template_name variable i need to add some extra var otherwise it should not add.
name: Run PPS Patch
template_run:
awx_url: “{{ awx_url }}”
username: “{{ username }}”
password: “{{ password }}”
scm_branch_for_agent: “{{ scm_branch_for_PPS }}”
project_name: “{{ project_name }}”
template_name: “{{ job_temp_name }}”
customEE_name: “{{ customEE_name }}”
inventory_name: “{{ inventory_name }}”
ip_add: “{{ vm_ipv4_address }}”
skip_tags: “{{ skip_tags }}”
extra_vars:
sat_client_id: “{{ sat_client_id }}”
sat_client_secret: “{{ sat_client_secret }}”
websec_prod_id: “{{ websec_prod_id }}”
websec_prod_secret: “{{ websec_prod_secret }}”
radius_secret: “{{ radius_secret }}”
{% if oracle in job_temp_name %}
ansible_distribution: “RedHat”
patch_enablerepo: “value”
standard_enablerepo: “value”
{% endif %}
playbook: “{{ patch_playbook }}”
when: not is_pps_template or (‘FAILED’ in status_check.tie_patch)
register: ppsstatus_check
until: “‘patch.yml completed successfully’ in ppsstatus_check.output”
retries: 3
delay: 10
tags:
pps_update
pps-patch
dnmvisser
(Dick Visser)
April 17, 2024, 10:04am
2
Hii,
I have never seen a task called "template_run", is this something
custom that you built?
utoddl
(Todd Lewis)
April 17, 2024, 2:01pm
3
I don’t know what consumes this (“template_run”?), but you could try this:
extra_vars:
sat_client_id: “{{ sat_client_id }}”
sat_client_secret: “{{ sat_client_secret }}”
websec_prod_id: “{{ websec_prod_id }}”
websec_prod_secret: “{{ websec_prod_secret }}”
radius_secret: “{{ radius_secret }}”
ansible_distribution: ‘{{ “RedHat” if “oracle” in job_temp_name else omit }}’
patch_enablerepo: ‘{{ “value” if “oracle” in job_temp_name else omit }}’
standard_enablerepo: ‘{{ “value” if “oracle” in job_temp_name else omit }}’
but I don’t really expect that to work.
You’d have to be pretty desperate to use this, but I would handle it using my “logical” filter:
- name: Run PPS Patch
template_run:
awx_url: "{{ awx_url }}"
username: "{{ username }}"
password: "{{ password }}"
scm_branch_for_agent: "{{ scm_branch_for_PPS }}"
project_name: "{{ project_name }}"
template_name: "{{ job_temp_name }}"
customEE_name: "{{ customEE_name }}"
inventory_name: "{{ inventory_name }}"
ip_add: "{{ vm_ipv4_address }}"
skip_tags: "{{ skip_tags }}"
<b># requires "ansible-galaxy collection install utoddl.logical"
extra_vars: "{{ extra_vars_ | utoddl.logical.logical }}"</b>
playbook: "{{ patch_playbook }}"
when: not is_pps_template or ('FAILED' in status_check.tie_patch)
vars:
extra_vars_:
sat_client_id: "{{ sat_client_id }}"
sat_client_secret: "{{ sat_client_secret }}"
websec_prod_id: "{{ websec_prod_id }}"
websec_prod_secret: "{{ websec_prod_secret }}"
radius_secret: "{{ radius_secret }}"
<b><<tmp:
- if:
- "{{ 'oracle' in job_temp_name }}"
- ansible_distribution: "RedHat"
- patch_enablerepo: "value"
- standard_enablerepo: "value"</b>
register: ppsstatus_check
until: "'patch.yml completed successfully' in ppsstatus_check.output"
retries: 3
delay: 10
tags:
- pps_update
- pps-patch
system
(system)
April 17, 2024, 2:28pm
4
This won't work as playbooks themselves are not jinja2 evaluated, only
keys inside a play are
{% if oracle in job_temp_name %}
ansible_distribution: "RedHat"
patch_enablerepo: "value"
standard_enablerepo: "value"
{% endif %}
An alternative would be:
ansible_distribution: "{{ oracle in job_temp_name|
ternary('RedHat', omit) }}"
patch_enablerepo: "{{ oracle in job_temp_name|
ternary('value', omit) }}"
standard_enablerepo: "{{ oracle in job_temp_name|
ternary('value', omit) }}"