From 2b217d3be908b7aa518f5eb3bd0bd2a40ee7963f Mon Sep 17 00:00:00 2001 From: rektide Date: Sun, 11 Nov 2012 18:05:48 +0000 Subject: [PATCH] Initial commit, ansible and debdev. --- ansible.pb | 8 +++++++ debdev.pb | 5 +++++ files/ansible/env.ansible | 6 +++++ files/ansible/hosts.localhost | 1 + files/ansible/manual.sh | 7 ++++++ tasks/ansible.tasks | 41 +++++++++++++++++++++++++++++++++++ tasks/debdev.tasks | 3 +++ tasks/xdg.vars.tasks | 7 ++++++ vars/ansible.vars | 10 +++++++++ 9 files changed, 88 insertions(+) create mode 100644 ansible.pb create mode 100644 debdev.pb create mode 100644 files/ansible/env.ansible create mode 100644 files/ansible/hosts.localhost create mode 100755 files/ansible/manual.sh create mode 100644 tasks/ansible.tasks create mode 100644 tasks/debdev.tasks create mode 100644 tasks/xdg.vars.tasks create mode 100644 vars/ansible.vars diff --git a/ansible.pb b/ansible.pb new file mode 100644 index 0000000..12099e8 --- /dev/null +++ b/ansible.pb @@ -0,0 +1,8 @@ +--- +- hosts: all + user: rektide + vars_files: + - "vars/ansible.vars" + tasks: + - include: "tasks/xdg.vars.tasks" + - include: "tasks/ansible.tasks" diff --git a/debdev.pb b/debdev.pb new file mode 100644 index 0000000..896b451 --- /dev/null +++ b/debdev.pb @@ -0,0 +1,5 @@ +--- +- hosts: all + sudo: true + tasks: + - include: "tasks/debdev.tasks" diff --git a/files/ansible/env.ansible b/files/ansible/env.ansible new file mode 100644 index 0000000..0b5d299 --- /dev/null +++ b/files/ansible/env.ansible @@ -0,0 +1,6 @@ +export ANSIBLE_HOSTS={{ANSIBLE_HOSTS_FILE}} +source {{INSTALL_DIR}}/hacking/env-setup +if [[ -e {{CONFIG_DIR}}/ansible.rc ]] +then + source {{CONFIG_DIR}}/ansible.rc +fi diff --git a/files/ansible/hosts.localhost b/files/ansible/hosts.localhost new file mode 100644 index 0000000..7b9ad53 --- /dev/null +++ b/files/ansible/hosts.localhost @@ -0,0 +1 @@ +127.0.0.1 diff --git a/files/ansible/manual.sh b/files/ansible/manual.sh new file mode 100755 index 0000000..bf1bb70 --- /dev/null +++ b/files/ansible/manual.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +mkdir -p ~/.local/opt ~/.local/bin ~/.config/ansible +[[ ! -d ~/.local/opt/ansible ]] && git clone https://github.com/ansible/ansible.git ~/.local/opt/ansible +[[ ! -e ~/.ansible/hosts.localhost ]] && echo 127.0.0.1 >> ~/.ansible/hosts.localhost +[[ ! -e ~/.ansible/hosts ]] && ln -s ~/.ansible/hosts.localhost ~/.ansible/hosts +[[ ! -e ~/.ansible/env.ansible ]] && cp env.ansible ~/.ansible/env.ansible diff --git a/tasks/ansible.tasks b/tasks/ansible.tasks new file mode 100644 index 0000000..4426864 --- /dev/null +++ b/tasks/ansible.tasks @@ -0,0 +1,41 @@ +--- +- name: insure CONFIG_DIR:$CONFIG_DIR exists + file: path=$CONFIG_DIR state=directory +- name: insure INSTALL_DIR:$INSTALL_DIR exists + file: path=$INSTALL_DIR state=directory +#### default hosts file +- name: copy DEFAULT_HOSTS:$DEFAULT_HOSTS into CONFIG_DIR:$CONFIG_DIR + copy: src=files/ansible/$DEFAULT_HOSTS dest=$CONFIG_DIR/ +- name: check for existing ANSIBLE_HOSTS_FILE:$ANSIBLE_HOSTS_FILE + shell: test -e $ANSIBLE_HOSTS_FILE && echo 1 || echo 0 + register: has_ansible_hosts_file +- name: default symlink ANSIBLE_HOSTS_FILE:$ANSIBLE_HOSTS_FILE to DEFAULT_HOSTS:$DEFAULT_HOSTS + file: src=$CONFIG_DIR/$DEFAULT_HOSTS dest=$ANSIBLE_HOSTS_FILE state=link + when_integer: ${has_ansible_hosts_file.stdout} == 0 +#### env setter helper +- name: check for existing CONFIG_DIR/ANSIBLE_ENV:$CONFIG_DIR/$ANSIBLE_ENV + shell: test -e $CONFIG_DIR/$ANSIBLE_ENV && echo 1 || echo 0 + register: has_ansible_env +- name: template ANSIBLE_ENV:$ANSIBLE_ENV into CONFIG_DIR:$CONFIG_DIR + template: src=files/ansible/$ANSIBLE_ENV dest=$CONFIG_DIR/$ANSIBLE_ENV + when_integer: ${has_ansible_env.stdout} == 0 +#### link to install +- name: check for existing CONFIG_DIR/INSTALL_LINK:$CONFIG_DIR/$INSTALL_LINK install link + shell: test -e $CONFIG_DIR/$INSTALL_LINK && echo 0 || echo 1 + register: need_install_link +- name: creating install link CONFIG_DIR/INSTALL_LINK:$CONFIG_DIR/$INSTALL_LINK to $INSTALL_DIR + file: src=$INSTALL_DIR dest=$CONFIG_DIR/$INSTALL_LINK state=link + when_integer: ${need_install_link.stdout} > 0 and ${has_xdg_config_dir.stdout} > 0 +#### xdg_config_dir/ansible install +- name: check whether xdg_config_dir exists qand is different from CONFIG_DIR:$CONFIG_DIR + shell: test "${has_xdg_config_dir.stdout}" == 1 -a "x${xdg_config_dir.stdout}" != "x$CONFIG_DIR" -a ! -e "${xdg_config_dir.stdout}/ansible" && echo 1 || echo 0 + register: need_config_link +- name: create xdg_config_dir:${xdg_config_dir.stdout} link to $CONFIG_DIR + file: src=$CONFIG_DIR dest=${xdg_config_dir.stdout}/ansible state=link + when_integer: ${need_config_link.stdout} > 0 +### install git +- name: git clone ansible repo + git: repo=$ANSIBLE_GIT dest=$INSTALL_DIR +- name: apt-get install ansible dependencies + apt: pkg=$DEPS state=latest + diff --git a/tasks/debdev.tasks b/tasks/debdev.tasks new file mode 100644 index 0000000..e09eaa9 --- /dev/null +++ b/tasks/debdev.tasks @@ -0,0 +1,3 @@ +--- +- name: mini-dinstall, debrelease, dput deps + apt: pkg=mini-dinstall,dput,pbuilder,devscripts,fakeroot state=latest diff --git a/tasks/xdg.vars.tasks b/tasks/xdg.vars.tasks new file mode 100644 index 0000000..e46913e --- /dev/null +++ b/tasks/xdg.vars.tasks @@ -0,0 +1,7 @@ +--- +- name: get xdg_config_dir + shell: echo ${XDG_CONFIG_HOME:-~/.config} + register: xdg_config_dir +- name: test xdg_config_dir + shell: test -d $xdg_config_dir && echo 1 || echo 0 + register: has_xdg_config_dir diff --git a/vars/ansible.vars b/vars/ansible.vars new file mode 100644 index 0000000..8208ba1 --- /dev/null +++ b/vars/ansible.vars @@ -0,0 +1,10 @@ +--- +DEPS: python-jinja2,python-yaml,python-paramiko,python-apt +ANSIBLE_GIT: https://github.com/ansible/ansible.git +INSTALL_DIR: ~/.local/opt/ansible +CONFIG_DIR: ~/.ansible +BIN_DIR: ~/.local/bin/ +ANSIBLE_HOSTS_FILE: $CONFIG_DIR/hosts +DEFAULT_HOSTS: hosts.localhost +ANSIBLE_ENV: env.ansible +INSTALL_LINK: lib