Skip to content

Instantly share code, notes, and snippets.

View lanky's full-sized avatar

Stuart Sears lanky

View GitHub Profile
---
# like this...
listofdict:
- key1: val1
key2: val2
- key1: val3
key2: val4
# or like this
listofdict2:
---
# vim: set ft=ansible:
- name: fetchstuff
hosts: localhost
gather_facts: no
tasks:
- name: fetch it
fetch:
src: "/tmp/{{ item.name}}"
dest: "/tmp/dest/{{ item.name }}"
# requires a version of python 2
# "ansibleenv" can be anything you want, it creates a directory and populates it with python things
virtualenv ansibleenv
source ansibleenv/bin/activate
pip install ansible
# now you should be able to run ansible commands as usual
---
# vim: set ft=ansible:
- name: find files
hosts: localhost
tasks:
- name: find local configuration files
find:
paths: resources-minimal
patterns: "*.yml"
register: configfiles
# first play
---
# vim: set ft=ansible:
- name: includes test
hosts: all
gather_facts: no
tasks:
- debug:
msg: "{{ item }}"
with_items: "{{ play_hosts }}"
---
# vim: set ft=ansible:
- name: play test
hosts: localhost
gather_facts: no
vars:
url: "http://wibble.wobbble.com:9091/some/path?param=value&param2=othervalue"
tasks:
- debug:
---
# vim: set ft=ansible:
- name: split things
hosts: localhost
gather_facts: no
vars:
myname: "foo-bar-1.3.4.5.tar"
tasks:
- name: splitit
---
# vim: set ft=ansible:
- name: subelements
hosts: localhost
gather_facts: no
vars:
static_hosts:
- host: test1
ips:
- 192.168.0.1
static_hosts:
- host: test1
- ip: 192.168.1.2
- ip: 192.168.1.2
- ip: 192.168.1.2
- host: test2
- ip: 127.0.0.1
- ip: 127.1.0.1
- ip: 127.1.0.2
- ip: 127.1.0.3
---
# vim: set ft=ansible:
- hosts: all
tasks:
- name: group hosts with random var
group_by:
key: random_var
when: random_var is defined
- name: prove it did stuff