Skip to content

Instantly share code, notes, and snippets.

@giovtorres
Created September 20, 2017 12:08
Show Gist options
  • Save giovtorres/04b0531080d027337f11e73e91da3f8a to your computer and use it in GitHub Desktop.
Save giovtorres/04b0531080d027337f11e73e91da3f8a to your computer and use it in GitHub Desktop.
Bootstrap files for a new ansible role after running `ansible-galaxy init` (Vagrant)
#/bin/bash
# Bootstrap files for a new ansible role after running `ansible-galaxy init`
echo "[+] Checking for .gitignore..."
if [ ! -f ".gitignore" ]; then
echo "[+] Not found. Creating .gitignore..."
cat > .gitignore << _EOF_
__pycache__
*.pyc
.molecule
.vagrant
.cache
._*
pytestdebug.log
*.swp
_EOF_
else
echo "[-] Skipping..."
fi
echo "[+] Checking for molecule.yml..."
if [ ! -f "molecule.yml" ]; then
echo "[+] Not found. Creating molecule.yml..."
cat > molecule.yml << _EOF_
---
driver:
name: vagrant
vagrant:
platforms:
- name: centos7
box: centos/7
- name: centos6
box: centos/6
providers:
- name: libvirt
type: libvirt
options:
memory: 1024
cpus: 1
driver: kvm
- name: virtualbox
type: virtualbox
options:
memory: 1024
cpus: 1
driver: vagrant
instances:
- name: $(basename $PWD)
ansible_groups:
- group1
verifier:
name: testinfra
_EOF_
else
echo "[-] Skipping..."
fi
echo "[+] Checking for tests directory..."
if [ ! -d "tests" ]; then
echo "[+] Creating tests directory..."
mkdir tests
else
echo "[-] Skipping..."
fi
echo "[+] Checking for test_default.py..."
if [ ! -f "tests/test_default.py" ]; then
echo "[+] Not found. Creating test_default.py..."
cat > tests/test_default.py << _EOF_
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory').get_hosts('all')
def test_foo(host):
pass
_EOF_
else
echo "[-] Skipping..."
fi
echo "[+] Checking for .travis.yml..."
if [ -f ".travis.yml" ]; then
echo "[+] Removing .travis.yml..."
rm -f .travis.yml
else
echo "[-] Skipping..."
fi
echo "[+] Checking for playbook.yml..."
if [ ! -f "playbook.yml" ]; then
echo "[+] Not found. Creating playbook.yml..."
cat > playbook.yml << _EOF_
---
- hosts: all
roles:
- $(basename $PWD)
_EOF_
else
echo "[-] Skipping..."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment