Skip to content

Instantly share code, notes, and snippets.

- name: Link check plugins
file: src={{ item.path }} dest={{ item.dest }} state=link
with_items:
- { path: '/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugins-cpu-checks-0.0.2/bin/check-cpu.rb', dest: '/etc/sensu/plugins/checks/check-cpu.rb' }
- { path: '/opt/sensu/embedded/lib/ruby/gems/2.0.0/gems/sensu-plugins-cpu-checks-0.0.2/bin/check-cpu.sh', dest: '/etc/sensu/plugins/checks/check-cpu.sh' }
notify: restart sensu-client
- hosts: all
tasks:
- name: create a temporary inventory group
group_by: key=os_{{ansible_os_family}}
- hosts: os_Windows
tasks:
# these tasks only apply to Windows
- hosts: all:!os_Windows
- name: test to see if ping works
ping:
ignore_errors: true
register: pingResult
- name: install simplejson if needed
raw: yum install -y python-simplejson
when: pingResult|failed
We set environment variables for the playbook run based on the type of cloud credential, so that the
modules can pick them up. If the modules are explicitly passed the keys, that will of course override
the cloud credential selection.
For AWS: AWS_ACCESS_KEY and AWS_SECRET_KEY
For Rackspace: RAX_USERNAME and RAX_API_KEY
For Google Compute Engine: GCE_EMAIL, GCE_PROJECT, and GCE_PEM_FILE_PATH
environment:
http_proxy: http://proxy.example.com:8080
my_other_var: boo
yet_another: argh
---
- hosts: all
connection: local
tasks:
- template: src=test-loop.j2 dest=./foo
host-one
host-two
host-three skip_facts=True
host-four
---
- hosts: localhost
tasks:
- name: get the pretty-printed git hash
command: "git log --pretty=format:'%h' -n 1"
register: githash
changed_when: False
- debug: msg="Playbook version is {{ githash.stdout }}"
# do you need this?
from jinja2 import contextfilter
class FilterModule(object):
''' Extra filters '''
def filters(self):
return {
'sort_hosts': self.sort_hosts,
}
- authorized_key: user=vagrant key="{{ lookup('file', item) }}"
with_first_found:
- "{{ security.ssh_key_file }}.pub"