Browse code

added way to display inventory vars for host to faq + some minor fixes/edits

Brian Coca authored on 2015/10/05 21:57:43
Showing 1 changed files
... ...
@@ -154,7 +154,15 @@ Ansible by default gathers "facts" about the machines under management, and thes
154 154
 
155 155
     ansible -m setup hostname
156 156
 
157
-This will print out a dictionary of all of the facts that are available for that particular host.
157
+This will print out a dictionary of all of the facts that are available for that particular host. You might want to pipe the output to a pager.
158
+
159
+.. _browse_inventory_vars:
160
+How do I see all the inventory vars defined for my host?
161
+
162
+You can see the resulting vars you define in inventory running the following command::
163
+
164
+    ansible -m debug -a "var=hostvars['hostname']" localhost
158 165
 
159 166
 .. _host_loops:
160 167
 
... ...
@@ -208,10 +216,10 @@ Anyway, here's the trick::
208 208
     {{ hostvars[groups['webservers'][0]]['ansible_eth0']['ipv4']['address'] }}
209 209
 
210 210
 Notice how we're pulling out the hostname of the first machine of the webservers group.  If you are doing this in a template, you
211
-could use the Jinja2 '#set' directive to simplify this, or in a playbook, you could also use set_fact:
211
+could use the Jinja2 '#set' directive to simplify this, or in a playbook, you could also use set_fact::
212 212
 
213 213
     - set_fact: headnode={{ groups[['webservers'][0]] }}
214
- 
214
+
215 215
     - debug: msg={{ hostvars[headnode].ansible_eth0.ipv4.address }}
216 216
 
217 217
 Notice how we interchanged the bracket syntax for dots -- that can be done anywhere.
... ...
@@ -221,7 +229,7 @@ Notice how we interchanged the bracket syntax for dots -- that can be done anywh
221 221
 How do I copy files recursively onto a target host?
222 222
 +++++++++++++++++++++++++++++++++++++++++++++++++++
223 223
 
224
-The "copy" module has a recursive parameter, though if you want to do something more efficient for a large number of files, take a look at the "synchronize" module instead, which wraps rsync.  See the module index for info on both of these modules.  
224
+The "copy" module has a recursive parameter, though if you want to do something more efficient for a large number of files, take a look at the "synchronize" module instead, which wraps rsync.  See the module index for info on both of these modules.
225 225
 
226 226
 .. _shell_env:
227 227
 
... ...
@@ -310,6 +318,7 @@ The no_log attribute can also apply to an entire play::
310 310
 Though this will make the play somewhat difficult to debug.  It's recommended that this
311 311
 be applied to single tasks only, once a playbook is completed.   
312 312
 
313
+
313 314
 I don't see my question here
314 315
 ++++++++++++++++++++++++++++
315 316