Skip to content

Instantly share code, notes, and snippets.

View lanky's full-sized avatar

Stuart Sears lanky

View GitHub Profile
---
- name: create a list and use it for something
hosts: all
vars:
existing_list: [ "1","2","3","4","5","6","7","8","9"]
ip_list: []
gather_facts: no
tasks:
- name: loop over hosts and create list of IP:PORT entries
set_fact:
{% for a, b in list1|zip(list2) %}
{{ a }}: {{ b }}
{% endfor %}`
---
# vim: set ft=ansible:
- name: matching line
vars:
stdout_lines:
- ""
- ""
- "db_instance : localhost"
- "db_type : mongoDB"
- "db_user : "
@lanky
lanky / grouptest.yml
Last active February 18, 2018 13:25
---
- name: groups
hosts: localhost
gather_facts: no
tasks:
- debug:
msg: "{{ item }}"
with_items: "{{ groups['all'] }}"
- command: echo "{{ item }}"
with_items: "{{ groups['all'] }}"
{# vim: set ft=jinja #}
{% for ntpserver in ntpservers %}
server {{ ntpserver }}
{% endfor %}
### other config ###
-------------
then for any given group you can just define ntpservers as a list:
---
- name: find stuff
hosts: localhost
tasks:
- find:
paths:
- /etc/pam.d
file_type: file
patterns:
- system*
- name: test stuff
hosts: all
gather_facts: no
tasks:
- name: set fact
set_fact:
myfact: "it is very good"
- name: test for it
---
- hosts: localhost
vars:
input: " THiS IS An ExaMpLE "
tasks:
- debug:
msg: "just lower: XXX{{ input | lower }}XXX"
- debug:
msg: "just trim: XXX{{ input | trim }}XXX"
- debug:
---
- hosts: all
tasks:
- debug:
msg: "{{ inventory_hostname }} sensu warn: {{ sensu_check_cpu_warning }}"
- debug:
msg: "{{ inventory_hostname }} sensu crit: {{ sensu_check_cpu_critical }}"
- debug:
docker_container:
docker_host: "{{ groups['etcd']|first }}:{{ docker_port }}"
image "myregistry:5000/redis:2.8.21"
env:
APP_NAME: "/CA/redis"
volumes:
- "/etc/hostname:/etc/hypervisor:ro"
name: rmaster01
hostname: rmaster01
network_mode: "{{ swarm_overlay_network }}"