Skip to content

Instantly share code, notes, and snippets.

- hosts: localhost
connection: local
gather_facts: false
vars:
things:
- "{{ foo }}"
- "{{ foob }}"
foo: "Hello"
tasks:
- name: debug things
[WARNING]: It is unnecessary to use '{{' in loops, leave variables in loop
expressions bare.
PLAY [localhost] **************************************************************
TASK: [debug things] **********************************************************
ok: [localhost] => {
"things": [
"Hello",
[WARNING]: It is unnecessary to use '{{' in loops, leave variables in loop
expressions bare.
PLAY [localhost] **************************************************************
TASK: [debug things] **********************************************************
ok: [localhost] => {
"things": [
"Hello",
#!/usr/bin/env python
import sys
from yaml import load
try:
from simplejson import dump
except ImportError:
from json import dump
- name: Collect public key
slurp: src="/var/lib/postgresql/.ssh/id_rsa.pub"
register: mykey
-
- name: Setup ssh keys
authorized_key: key="{{mykey.content.decode('base64')}}" user="backup"
delegate_to: "{{item}}"
with_items: groups['backup']
ansible -m getent -a 'database=passwd key=bcoca' -i 'localhost,' all -c local
localhost | success >> {
"ansible_facts": {
"getent_passwd": {
"bcoca": [
"x",
"1000",
"1000",
"",
"/home/bcoca",
- hosts: legacy_servers
gather_facts: false
tags:
- legacy
tasks:
- name: get metadata on legacy servers
shell: >
hostname; len=`hostname | wc -c` ; export len; perl -E 'say "=" x ($ENV{"len"} - 1)' ;
#play.yml
---
- hosts: localhost
connection: local
gather_facts: false
roles:
- test
tasks:
- debug: msg="ran untagged"
Github workflow
===============
Fork a repo using github GUI, now there are 2 repos you are going to deal with, 1 the repo under your user bcoca/ansible and the main project ansible/ansible
* Clone the ansible repo (this is now 'origin'), the following assumes youre ssh keys are setup.
There are several ways of doing this and organizing your workflow, this is just 'my way' and it can be used with several variations.
Those with direct commit access might want to reverse this, you cannot count on direct pushes being rejected.
#>git clone git@github.com:ansible/ansible
 ansible -m stat -a 'path=/home/bcoca/work/ansible/tmp' localhost
localhost | SUCCESS => {
"changed": false,
"stat": {
"atime": 1460579289.7836845,
"ctime": 1460579289.7836845,
"dev": 2083,
"exists": true,
"gid": 1000,
"gr_name": "bcoca",