This file contains hidden or 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
from jinja2 import contextfilter | |
class FilterModule(object): | |
''' Extra filters ''' | |
def filters(self): | |
return { | |
'deeplist': self.deeplist, | |
} |
This file contains hidden or 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
- hosts: web | |
serial: 1 | |
tasks: | |
- include: includes/{{ inventory_class }}_web_update.yml | |
- hosts: core | |
serial: 1 | |
tasks: |
This file contains hidden or 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
--- | |
- name: Configure UFW for baseline access | |
ufw: rule=allow | |
from_ip="{{ item.ip }}" | |
to_port="{{ item.port }}" | |
state=enabled | |
with_items: | |
- { ip: "10.0.0.0/8", port: "any" } | |
- { ip: "172.16.0.0/12", port: "any" } | |
- { ip: "192.168.0.0/16", port: "any" } |
This file contains hidden or 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
- command: grep string file | |
ignore_errors: yes | |
register: result | |
# How to set this fact so that it is a boolean variable, not a string? | |
- set_fact: | |
got_string: "{{ (result|success)|bool }}" |
This file contains hidden or 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
Make a template file called, say, rules-generator.j2: | |
{% for cidr_ip in aws_trusted_networks %} | |
- proto: tcp | |
from_port: 22 | |
to_port: 22 | |
cidr_ip: {% cidr_ip %} | |
{% endfor %} | |
In your playbook, do: |
This file contains hidden or 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
--- | |
- name: Ensure git is installed (Debian). | |
apt: name={{ item }} state=installed | |
with_items: git_packages | |
# Install git from source when git_install_from_source is true. | |
- include: install-from-source.yml | |
when: git_install_from_source == true |
This file contains hidden or 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
--- | |
- hosts: all | |
connection: local | |
vars: | |
role: foo | |
descriptions: | |
foo: "this is the description for foo" | |
bar: "this is the description for bar" |
This file contains hidden or 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
- name: test file existence | |
stat: file=filename.txt | |
register: st | |
- name: do something | |
shell: ... | |
when: st.stat.exists |
This file contains hidden or 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
- name: do something not sudo | |
command: echo hello | |
sudo: no |
This file contains hidden or 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
Timothys-MacBook-Pro:ansible-test tgerla$ ansible-playbook -i localhost, test-vars.yml | |
PLAY [localhost] ************************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [localhost] | |
TASK: [debug msg="VLAN for our IP is {{ip_vlan_mapping[ip]}}"] **************** | |
ok: [localhost] => { | |
"msg": "VLAN for our IP is 997" |