Skip to content

Commit bac10dd

Browse files
Add example to use host parameters via Ansible
1 parent 3dee2a2 commit bac10dd

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

guides/common/modules/proc_running-an-ansible-playbook.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ For more information, see xref:executing-a-remote-job_{context}[].
3636
For more information, see the following resources:
3737
** xref:importing-an-ansible-playbook-by-name_{context}[]
3838
** xref:importing-all-available-ansible-playbooks_{context}[]
39+
* xref:host-parameters-in-ansible-playbooks[]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
:_mod-docs-content-type: REFERENCE
2+
3+
[id="host-parameters-in-ansible-playbooks"]
4+
= Host parameters in Ansible Playbooks
5+
6+
You can use host parameters from {Project} in Ansible Playbooks.
7+
8+
.Example Ansible Playbook to access host parameters
9+
[source, yaml, options="nowrap", subs="+quotes,verbatim,attributes"]
10+
----
11+
---
12+
- name: "Ansible Playbook to access host parameters"
13+
hosts: all
14+
tasks:
15+
- name: "Use a host parameter"
16+
ansible.builtin.debug:
17+
var: hostvars[inventory_hostname]["_My_Host_Parameter_"]
18+
...
19+
----
20+
21+
You can set the value of _My_Host_Parameter_ to an ERB template, for example, `<%= @host.capabilities.include?(:snapshots) %>`.
22+
When {Project} renders the Ansible Playbook, it will load the value of the variable _My_Host_Parameter_, render the ERB template, and provide the value to Ansible.
23+
24+
.Example Ansible Playbook to use ERB templating
25+
[source, yaml, options="nowrap", subs="+quotes,verbatim,attributes"]
26+
----
27+
---
28+
- name: "Ansible Playbook to access host parameters and render the ERB template"
29+
hosts: all
30+
tasks:
31+
- name: "Use ERB templating"
32+
ansible.builtin.debug:
33+
var: hostvars[inventory_hostname]["_My_Host_Parameter_"]
34+
...
35+
----
36+
37+
.Additional resources
38+
* {ProvisioningDocURL}Host_Parameter_Hierarchy_provisioning[Host parameter hierarchy] in _{ProvisioningDocTitle}_

guides/doc-Managing_Configurations_Ansible/master.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ include::common/assembly_using-ansible-roles.adoc[leveloffset=+1]
1515

1616
include::common/modules/proc_running-an-ansible-playbook.adoc[leveloffset=+1]
1717

18+
include::common/modules/ref_host-parameters-in-ansible-playbooks.adoc[leveloffset=+2]
19+
1820
include::common/assembly_configuring-and-setting-up-remote-jobs.adoc[leveloffset=+1]
1921

2022
include::common/assembly_integrating-awx.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)