Skip to content

Instantly share code, notes, and snippets.

@halberom
halberom / output
Last active October 6, 2017 11:36
ansible - jsonifying yaml
$ ansible-playbook play.yml
PLAY [localhost] ***************************************************************************************************************************************************************************************************************************************************************
TASK [debug] *******************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": "[{\"foo\": \"bar\", \"abc\": \"xyz\"}, {\"foo\": 123, \"abc\": 456}]"
}
TASK [command] *****************************************************************************************************************************************************************************************************************************************************************
@halberom
halberom / ansible.cfg
Last active June 18, 2021 07:50
ansible - testing constructed inventory plugin
[inventory]
enable_plugins = ini, constructed
@halberom
halberom / output
Created October 5, 2017 13:39
ansible - type is not maintained, even with |int
TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [debug] *******************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"ansible_memtotal_mb": 16384
}
TASK [command] *****************************************************************************************************************************************************************************************************************************************************************
changed: [localhost]
@halberom
halberom / foobar.yml
Last active October 2, 2017 15:48
ansible - basic test of including playbook with vars
---
# vars/foobar.yml
foobar_var: bob
@halberom
halberom / ansible.cfg
Last active January 23, 2020 06:56
ansible - custom filters to test type
[defaults]
filter_plugins = plugins/filter
test_plugins = plugins/test
@halberom
halberom / alternative_play.yml
Last active September 21, 2017 11:35
ansible - broken role vars?
# This one works with the include_/import_ interestingly
---
- hosts: localhost
gather_facts: False
connection: local
vars:
rolename: test2
roles:
- test1
@halberom
halberom / output
Last active December 19, 2017 10:34
ansible - using assert with regex and quotes
PLAY [localhost] **********************************************************************************************************************
TASK [assert] *************************************************************************************************************************
ok: [localhost] => (item=\') => {
"changed": false,
"item": "\\'",
"msg": "All assertions passed"
}
ok: [localhost] => (item=\") => {
"changed": false,
@halberom
halberom / efs_targets.j2
Last active May 18, 2023 10:22
ansible - example of using lookup and a template to generate dynamic list entries for modules
#jinja2:trim_blocks: True, lstrip_blocks: True
targets:
{% for privnet in all_private_subnets %}
- subnet_id: "{{ privnet }}"
security_groups: [ "{{ sg.group_id }}" ]
{% endfor %}
{% for pubnet in all_public_subnets %}
- subnet_id: "{{ pubnet }}"
security_groups: [ "{{ sg.group_id }}" ]
{% endfor %}
@halberom
halberom / mail_body.j2
Created September 7, 2017 09:51
ansible - example of using mail module to send one email for all hosts
# templates/mail_body.j2
{% for host in play_hosts %}
The {{ host }} says {{ hostvars[host]['result']['stdout'] }}
{% endfor %}
@halberom
halberom / 00_play.yml
Created September 5, 2017 14:45
Ansible - example of grabbing a key of a hash where an attribute does not equal something
---
- hosts: localhost
connection: local
gather_facts: False
vars:
myvar:
- name: qwe
att1: 1
att2: user_1
- name: asd