Created
September 6, 2018 10:27
-
-
Save oxidizeddreams/7077ef4a00d0f9cc361163da13381360 to your computer and use it in GitHub Desktop.
ansible_advanced_things
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
# network | |
# ipaddr: possible use case to verify lists of ip addresses from a database SELECT | |
# Example list of values | |
test_list = ['192.24.2.1', 'host.fqdn', '::1', '192.168.32.0/24', 'fe80::100/10', True, '', '42540766412265424405338506004571095040/64'] | |
# {{ test_list | ipaddr }} | |
['192.24.2.1', '::1', '192.168.32.0/24', 'fe80::100/10', '2001:db8:32c:faad::/64'] | |
# map: possible use case to filter subnets | |
vpc_subnet_list: | |
- enable: true | |
- | |
subnet_name: "{{ aws_environment }}-public-{{ aws_region }}a" | |
subnet_cidr: 10.168.104.0/21 | |
subnet_az: "{{ aws_region }}a" | |
subnet_create: true | |
- | |
subnet_name: "{{ aws_environment }}-private-{{ aws_region }}a" | |
subnet_cidr: 10.168.112.0/21 | |
subnet_az: "{{ aws_region }}a" | |
subnet_create: true | |
tasks: | |
- debug: | |
msg: "{{ vpc_subnet_list | map(attribute='subnet_cidr') | list }}" | |
# python string method | |
# note: In contrast to filters, methods are not attached to variables with a pipe, but with dot notation. | |
vars: | |
- mystring: foobar something | |
- name: endswith method | |
debug: | |
msg: "{{ mystring.endswith('thing') }}" | |
# python split method: possible use case around ip address manipulation (cidr block calculations) | |
# note: to attach a method to a filtered object, another set of brackets – ( ) – is needed | |
vars: | |
- myaddresses: ['192.24.2.1', '10.0.3.5', '171.17.32.1'] | |
tasks: | |
- name: get last element of 10* IP | |
debug: | |
msg: "{{ (myaddresses|ipaddr('10.0.0.0/8'))[0].split('.')[-1] }}" | |
... | |
TASK [get last element of 10* IP] ************************************************************** | |
ok: [localhost] => { | |
"msg": "5" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment