Skip to content

Instantly share code, notes, and snippets.

---
# This is a single playbook.
- name: all servers
hosts: all
sudo: true
roles:
- { role: foo, tags: [common, foo] }
- { role: bar, tags: [common ,bar] }
[a, b, c]|difference([b]) will return [a, c]
- stat: path=somewhere/awesome
register: foo_stats
- include: world.yml
# host_vars/all.yml
foo_master = "{{ groups['blah'][0] }}"
# ^ For some reason foo_master is ignored here
@AntelopeSalad
AntelopeSalad / foo
Last active August 29, 2015 14:01
$ mkdir mybook && cd mybook && mkdir -p roles/common/tasks && mkdir -p roles/common/files && wget https://gist.github.com/AntelopeSalad/d9a4c92805b478323bfc/raw/site.yml && cd roles/common/tasks && wget https://gist.github.com/AntelopeSalad/d9a4c92805b478323bfc/raw/main.yml && cd ../files && wget https://gist.github.com/AntelopeSalad/d9a4c92805b…
# mybook/roles/common/files/foo
foobar
hosts_file = File.readlines('/path/to/hosts')
group_names = []
host_names = []
hosts_file.each do |line|
line.chomp!
first_char = line[0]
last_char = line[-1, 1]
[defaults]
transport = ssh
[ssh_connection]
ssh_args = -o ForwardAgent=yes
@AntelopeSalad
AntelopeSalad / galaxy_workflow.md
Last active August 29, 2015 14:00
Surely there is a better way?
  • You are working on your playbook at ~/dev/mycoolplaybook
  • You decide to extract a role to post it on the galaxy
    • Copy coolrole from mycoolplaybook
    • Copy to ~/somewhere/github/mycoolrole
      • Git init the directory and add in the galaxy metadata.
      • Push it to github.
      • Add it to the galaxy.
    • Galaxy install the role.
    • Rename the role declaration in your site.yml to match the new name.
  • Run the role to make sure it works after all of that shuffling around.
deploy@ansible-test:/usr/local/rvm$ id
uid=1000(deploy) gid=1000(deploy) groups=1000(deploy),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),111(lpadmin),112(sambashare)
- debug: var=version_init.stdout != v{{app_node_version}}
TASK: [app | debug var=version_init.stdout != v{{app_node_version}}] **********
ok: [192.168.1.12] => {
"item": "",
"version_init.stdout": "v0.10.27"
}