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 / 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"
}
@halberom
halberom / output
Created July 24, 2014 14:42
example play including role when conditional
# when 'is not defined'
PLAY [foo] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [role1 | debug msg="doing something in foo.yml"] ************************
skipping: [localhost]
@halberom
halberom / output
Created August 2, 2014 14:41
ansible - use variable in service name
PLAY [foo] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [service name="ntpd" state=restarted] ***********************************
changed: [localhost]
PLAY RECAP ********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0