forked from gc3-uzh-ch/ansible-playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e09af7
commit b62b2de
Showing
4 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
################ | ||
# DRBD example # | ||
################ | ||
# | ||
# This is a module created by us, and present in the `modules` | ||
# directory. This is just an example on how to use it. However, the | ||
# module is documented in the comments at the beginning of the file. | ||
# | ||
# This is a minimal example: | ||
|
||
- hosts: all | ||
tasks: | ||
- action: drbd name=resourcename disk=/dev/drbd1 | ||
device=/dev/sdb | ||
address0=1.1.1.1:7789 address1=1.1.1.2:7789 | ||
|
||
# while this will define also the optional variables. Note that the | ||
# two modules produce the same results, considering the value I've put | ||
# in this second example in order to show you the default behavior. | ||
|
||
- hosts: all | ||
tasks: | ||
- action: drbd name=resourcename dest=/etc/drbd.d/resourcename.res | ||
disk0=/dev/drdb1 disk1=/dev/drdb1 | ||
device0=/dev/sdb device1=/dev/sdb | ||
address0=1.1.1.1:7789 address1=1.1.1.2:7789 | ||
peer0=1.1.1.1:7789 peer1=1.1.1.2:7789 | ||
metadisk0=internal metadisk1=internal | ||
|
||
# The output produced should be found in /etc/drbd.d/resousrcename.res | ||
# and should looks like: | ||
# | ||
# resource resourcename { | ||
# on 1.1.1.1:7789 { | ||
# address 1.1.1.1:7789; | ||
# device /dev/sdb; | ||
# disk /dev/drdb1; | ||
# meta-disk internal; | ||
# } | ||
# on 1.1.1.2:7789 { | ||
# address 1.1.1.2:7789; | ||
# device /dev/sdb; | ||
# disk /dev/drdb1; | ||
# meta-disk internal; | ||
# } | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
####################### | ||
# Nested VARS example # | ||
####################### | ||
# | ||
# This example is used to explain how you can call nested variables | ||
# (like, an item of a dictionary) using ansible prior v1.2. It may be | ||
# a bit tricky because of the way ansible does the expansion of th | ||
# evariables... | ||
# | ||
# Bascially, to expand `hostvars[item]` where `hostvars` is a | ||
# dictionary-like object and `item` is a variable, you have to do: | ||
# | ||
# ${hostvars.{$item}} | ||
# | ||
# Note that the expansion of the dictionary is done with `${...}` | ||
# while the expansion of the attribute of the dictionary is done with | ||
# `{$...}`. | ||
# | ||
# The following example will define a dictionary `hosts`: | ||
# | ||
# hosts = { 'a': {'b': 'c'}} | ||
# | ||
# and try to print `hosts['a']['b']` | ||
# | ||
- hosts: all | ||
vars: | ||
hosts: | ||
a: | ||
b: c | ||
x: a | ||
y: b | ||
tasks: | ||
- debug: msg="${hosts.{$x}.{$y}}" | ||
|
||
# The original use case I used for this was taken from this task, in | ||
# which I wanted to produce an ``/etc/hosts`` file starting from the | ||
# data sotred in the inventory, adding or updating the IP addresses of | ||
# all the known hosts. | ||
# | ||
# - hosts: all | ||
# connection: local | ||
# tasks: | ||
# - lineinfile: dest=/tmp/hostfile regexp=".* $item .*" line="${hostvars.{$item}.ansible_default_ipv4.address} $item " | ||
# with_items: $hostvars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
`groups` | ||
======== | ||
{% for key, value in groups.items() %} | ||
{{ key }} : {{ value }} | ||
{% endfor %} | ||
|
||
groups: | ||
{% for group in group_names %} | ||
{{ group }} | ||
{% endfor %} | ||
|
||
`hostvars` | ||
========== | ||
|
||
{% for key, value in hostvars.items() -%} | ||
|
||
{{ key }}: | ||
{% if value is mapping %} | ||
{%- for key2, value2 in value.items() %} | ||
|
||
{{ key2 }}: | ||
{% if value2 is string %} | ||
'{{ value2 }}' | ||
{% elif value2 is mapping %} | ||
{%- for key3, value3 in value2.items() %} | ||
|
||
{{ key3 }}: | ||
{% if value3 is string %} | ||
'{{ value3 }}' | ||
{% else %} | ||
{{ value3 }} | ||
{% endif %} | ||
{% endfor %} | ||
{% else %} | ||
{{ value2 }} | ||
{% endif %} | ||
{% endfor %} | ||
{% elif value is string %} | ||
'{{ value }}' | ||
{% else %} | ||
{{ value }} | ||
{% endif %} | ||
{% endfor %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
########################### | ||
# Storing facts to a file # | ||
########################### | ||
# | ||
# This will store some information in `variables.txt` | ||
# | ||
# In most cases you may want to use instead: | ||
# | ||
# ansible -m setup -t ./variables.d all | ||
# | ||
# which will store in directory `variables.d` all facts gathered by | ||
# the `setup` module. | ||
# | ||
# However, the template system will also get facts or variables set by | ||
# modules executed before in the playbook. | ||
|
||
- hosts: all | ||
tasks: | ||
- template: src=variables.j2 dest=./variables.txt |