Skip to content

Instantly share code, notes, and snippets.

View lanky's full-sized avatar

Stuart Sears lanky

View GitHub Profile
@lanky
lanky / filemod
Last active August 29, 2015 14:24
- hosts: all
name: test stat output
tasks:
- name: check last change to file
stat:
path: '/etc/fstab'
register: st
- debug:
msg: "File last modified {{ansible_date_time.epoch|int - st.stat.mtime|int }} seconds ago"
- name: copy lots of stuff
copy:
src: {{ item.name }}
dest: {{ item.path }}
with_items:
- name: rsyslog.conf
path: /etc
- name: remote.conf
path: /etc/rsyslog.d
# assuming a group called rsyslog_servers of which your target host is a member
# with this content ina vars file somewhere
rsyslog_server_files:
- rsyslog.conf
- rsyslog.d/00-allowedhost.conf
- rsyslog.d/50-default.conf
# and some thing like this in your role
- name: deploy rsyslog config
#!/usr/bin/env python
from ansible import errors
import types
def split(input, sep=' ', maxsplit=0):
if not isinstance(input, types.StringTypes) or not isinstance(sep, types.StringTypes):
raise errors.AnsibleFilterError('split only operates on strings')
if maxsplit > 0:
return input.split(sep, maxsplit)
return input.split(sep)
---
- name: test loops
hosts: somegroup
tasks:
- name: api thingy
module:
args: values
delegate_to: someother_host
@lanky
lanky / testloop.yml
Last active September 7, 2016 16:41
---
- name: create a list and use it for something
hosts: all
vars:
ip_list: []
gather_facts: no
tasks:
- name: loop over hosts and create list of IP:PORT entries
set_fact:
ip_list: "{{ ip_list }} + [ '{{ '%s:6379' | format(item) }}' ]"
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 }}"
---
- hosts: all
tasks:
- debug:
msg: "{{ inventory_hostname }} sensu warn: {{ sensu_check_cpu_warning }}"
- debug:
msg: "{{ inventory_hostname }} sensu crit: {{ sensu_check_cpu_critical }}"
- debug:
---
- 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:
- name: test stuff
hosts: all
gather_facts: no
tasks:
- name: set fact
set_fact:
myfact: "it is very good"
- name: test for it