Skip to content

Instantly share code, notes, and snippets.

- name: ensure swap file is allocated
command: dd if=/dev/zero of=/swapfile bs=1M count={{ common_swap_size }}
when: ansible_swaptotal_mb < 1
- name: ensure swap file is created
command: mkswap /swapfile
when: ansible_swaptotal_mb < 1
- name: ensure swap file is added to fstab
action: lineinfile dest=/etc/fstab regexp="swapfile" line="/swapfile none swap sw 0 0" state=present
# this works because on the remote machine /home/deploy exists (in this case common_user == 'deploy')
- name: ensure a deploy user is created
user: name={{ common_user }} comment="Mr. Deploy"
# this fails and I'm unsure of the syntax for the key , but the error seems to be related to the user?
- authorized_key: user={{ common_user }} key="{{ lookup('file', {{ common_ssh_key_path }}) }}"
$ ansible-playbook -i hosts site.yml
ERROR: expecting dict; got: h
# common/defaults/main.yml
---
common_ssh_port: 44444
# group_vars/all
---
ansible_ssh_port: "{{ common_ssh_port }}"
---
foo_project:
app:
domain:
name: foo.com
=====
vs.
=====
---
- name: restart nginx
service: name=nginx state=restarted
- name: restart fail2ban
service: name=fail2ban state=restarted
- hosts: all
tasks:
- name: Open the correct IPTables ports
lineinfile: dest=/etc/sysconfig/iptables
regexp="^-A INPUT -p {{item.protocol}} -m {{item.protocol}} --dport {{item.port}} -j ACCEPT$"
line="-A INPUT -p {{item.protocol}} -m {{item.protocol}} --dport {{item.port}} -j ACCEPT"
insertafter="^:OUTPUT ACCEPT \[\d*:\d*\]$"
with_items:
- { protocol: tcp, port: 80 }
- { protocol: tcp, port: 443 }
# roles/database/handlers/main.yml
---
- name: restart postgres
service: name=postgres state=restarted
@AntelopeSalad
AntelopeSalad / bootstra-ansible.sh
Last active August 29, 2015 14:00
Trying to install ansible without using a package manager to get the latest version
#!/bin/bash
# bootstrap-ansible.sh: download and build Ansible on Debian host
# https://github.com/ginas/ginas/
set -e
# Create temporary directory for build
build_dir=$(mktemp -d)
trap "rm -rf ${build_dir}" EXIT