Skip to content

Instantly share code, notes, and snippets.

@halberom
halberom / main.yml
Created May 28, 2014 10:34
call role with arg, set_fact
# /etc/ansible/roles/tmp/tasks/main.yml
---
- name: do something with passed var
debug: var=myothervar
- name: do something with set_fact var
debug: var=myvar
@halberom
halberom / output
Created May 28, 2014 11:07
yet another set_fact pass to role var thingy
PLAY [all] ********************************************************************
TASK: [register a fact] *******************************************************
ok: [localhost]
PLAY [all] ********************************************************************
TASK: [tmp | do something with passed var] ************************************
ok: [localhost] => {
"item": "",
@halberom
halberom / output
Created May 29, 2014 14:21
accessing a set_fact var
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [role1 | set_fact foo=bar] **********************************************
ok: [localhost]
TASK: [role2 | debug var=foo] *************************************************
ok: [localhost] => {
@halberom
halberom / etcd_tasks_main.yml
Last active August 29, 2015 14:02
conditional include idea
---
- include: install.yml
when: 'etcd' in groups
- include: cleanup.yml
when: 'etcd' not in groups
@halberom
halberom / main.yml
Created June 2, 2014 13:21
example role vars file
# head -n3 roles/hosts-canonical/vars/main.yml
---
ipaddr_to_hostname:
10.0.0.2: ['c0w2', 'l2']
10.0.0.3: ['alt-gateway']
@halberom
halberom / output
Created June 5, 2014 10:36
ansible - using lookup to get a date timestamp into a variable
...
TASK: [debug var=mydate] ******************************************************
ok: [localhost] => {
"mydate": "20140605101824"
}
...
@halberom
halberom / output
Created June 5, 2014 14:58
ansible - example of doing something if a file exists
# the file doesn't exist
TASK: [debug var=foo] *********************************************************
ok: [localhost] => {
"foo": {
"changed": false,
"invocation": {
"module_args": "path=/tmp/file",
"module_name": "stat"
},
@halberom
halberom / main.yml
Created June 6, 2014 09:49
ansible - example of multiple plays, one creating a new group
# roles/do_something/tasks/main.yml
---
- name: do something
command: grep foo /tmp/bar
register: result
- name: add host to new group based on result
add_host: hostname=inventory_hostname group_name=mynewgroup
when: result.stdout == 'whatever'
@halberom
halberom / play.yml
Last active August 29, 2015 14:02
ansible - example of finding files on remote and linking
---
- hosts: all
vars:
mypath: ~/.zprezto/runcoms
tasks:
- name: Find runcom Prezto files
shell: find {{ mypath }} -type f -name 'z*'
register: file_list
# verify what's returned first
@halberom
halberom / output
Created June 14, 2014 20:00
ansible - setting a source ip var based on other interface vars
TASK: [debug var=source_ip] ***************************************************
ok: [localhost] => {
"source_ip": "127.0.0.1"
}