commit 33ed1c69f0a091ae6bb615bf5ac3739ed7412b80 Author: Elijah Lazkani Date: Sun May 27 23:01:28 2018 -0400 Second commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cff59f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,106 @@ +*.retry + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/Ansible/pleasure.yml b/Ansible/pleasure.yml new file mode 100644 index 0000000..0244c31 --- /dev/null +++ b/Ansible/pleasure.yml @@ -0,0 +1,4 @@ +- hosts: local + become: yes + roles: + - base diff --git a/Ansible/roles/base/.yamllint b/Ansible/roles/base/.yamllint new file mode 100644 index 0000000..3a2255e --- /dev/null +++ b/Ansible/roles/base/.yamllint @@ -0,0 +1,13 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + # NOTE(retr0h): Templates no longer fail this lint rule. + # Uncomment if running old Molecule templates. + # truthy: disable diff --git a/Ansible/roles/base/defaults/fedora.yml b/Ansible/roles/base/defaults/fedora.yml new file mode 100644 index 0000000..8a58e81 --- /dev/null +++ b/Ansible/roles/base/defaults/fedora.yml @@ -0,0 +1,5 @@ +--- +common_repo_package_list: + - git + - fish + - vim-enhanced diff --git a/Ansible/roles/base/defaults/main.yml b/Ansible/roles/base/defaults/main.yml new file mode 100644 index 0000000..55666f9 --- /dev/null +++ b/Ansible/roles/base/defaults/main.yml @@ -0,0 +1,7 @@ +--- +user: elijah +user_home: "/home/{{ user }}" +workdir_path: "{{ user_home }}/sandbox" +virtualenvs_path: "{{ user_home }}/.virtualenvs" + +omf_git_repo: https://github.com/oh-my-fish/oh-my-fish diff --git a/Ansible/roles/base/defaults/ubuntu.yml b/Ansible/roles/base/defaults/ubuntu.yml new file mode 100644 index 0000000..2d60e70 --- /dev/null +++ b/Ansible/roles/base/defaults/ubuntu.yml @@ -0,0 +1,5 @@ +--- +common_repo_package_list: + - git + - fish + - vim diff --git a/Ansible/roles/base/handlers/main.yml b/Ansible/roles/base/handlers/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/Ansible/roles/base/handlers/main.yml @@ -0,0 +1 @@ +--- diff --git a/Ansible/roles/base/meta/main.yml b/Ansible/roles/base/meta/main.yml new file mode 100644 index 0000000..41be6ba --- /dev/null +++ b/Ansible/roles/base/meta/main.yml @@ -0,0 +1,64 @@ +--- +galaxy_info: + author: Elijah Lazkani + description: DevOps Engineer + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: BSD + + min_ansible_version: 2.5 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # Optionally specify the branch Galaxy will use when accessing the GitHub + # repo for this role. During role install, if no tags are available, + # Galaxy will use this branch. During import Galaxy will access files on + # this branch. If Travis integration is configured, only notifications for this + # branch will be accepted. Otherwise, in all cases, the repo's default branch + # (usually master) will be used. + # github_branch: + + # + # platforms is a list of platforms, and each platform has a name and a list of versions. + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + platforms: + - name: Febora + versions: + - 28 + - name: Ubuntu + versions: + - bionic + + #galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +#dependencies: [] +# List your role dependencies here, one per line. Be sure to remove the '[]' above, +# if you add dependencies to this list. diff --git a/Ansible/roles/base/molecule/default/Dockerfile.j2 b/Ansible/roles/base/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..19692c2 --- /dev/null +++ b/Ansible/roles/base/molecule/default/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/Ansible/roles/base/molecule/default/INSTALL.rst b/Ansible/roles/base/molecule/default/INSTALL.rst new file mode 100644 index 0000000..e26493b --- /dev/null +++ b/Ansible/roles/base/molecule/default/INSTALL.rst @@ -0,0 +1,16 @@ +******* +Install +******* + +Requirements +============ + +* Docker Engine +* docker-py + +Install +======= + +.. code-block:: bash + + $ sudo pip install docker-py diff --git a/Ansible/roles/base/molecule/default/molecule.yml b/Ansible/roles/base/molecule/default/molecule.yml new file mode 100644 index 0000000..ec0908e --- /dev/null +++ b/Ansible/roles/base/molecule/default/molecule.yml @@ -0,0 +1,22 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: Fedora + image: fedora:28 + - name: Ubuntu + image: ubuntu:bionic +provisioner: + name: ansible + lint: + name: ansible-lint +scenario: + name: default +verifier: + name: testinfra + lint: + name: flake8 diff --git a/Ansible/roles/base/molecule/default/playbook.yml b/Ansible/roles/base/molecule/default/playbook.yml new file mode 100644 index 0000000..140084a --- /dev/null +++ b/Ansible/roles/base/molecule/default/playbook.yml @@ -0,0 +1,11 @@ +--- +- name: Converge + hosts: all + pre_tasks: + - name: Create user "{{ user }}" + user: + name: "{{ user }}" + home: "{{ user_home }}" + state: present + roles: + - role: base diff --git a/Ansible/roles/base/molecule/default/tests/test_default.py b/Ansible/roles/base/molecule/default/tests/test_default.py new file mode 100644 index 0000000..eedd64a --- /dev/null +++ b/Ansible/roles/base/molecule/default/tests/test_default.py @@ -0,0 +1,14 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_hosts_file(host): + f = host.file('/etc/hosts') + + assert f.exists + assert f.user == 'root' + assert f.group == 'root' diff --git a/Ansible/roles/base/tasks/common.yml b/Ansible/roles/base/tasks/common.yml new file mode 100644 index 0000000..1cd162e --- /dev/null +++ b/Ansible/roles/base/tasks/common.yml @@ -0,0 +1,14 @@ +--- +- name: Create work directory + file: + path: "{{ workdir_path }}" + owner: "{{ user }}" + group: "{{ user }}" + state: directory + +- name: Create virtualenvs directory + file: + path: "{{ virtualenvs_path }}" + owner: "{{ user }}" + group: "{{ user }}" + state: directory diff --git a/Ansible/roles/base/tasks/fedora.yml b/Ansible/roles/base/tasks/fedora.yml new file mode 100644 index 0000000..4000192 --- /dev/null +++ b/Ansible/roles/base/tasks/fedora.yml @@ -0,0 +1,5 @@ +--- +- name: Install Fedora packages + dnf: + name: "{{ common_repo_package_list }}" + state: latest diff --git a/Ansible/roles/base/tasks/fish.yml b/Ansible/roles/base/tasks/fish.yml new file mode 100644 index 0000000..7932835 --- /dev/null +++ b/Ansible/roles/base/tasks/fish.yml @@ -0,0 +1,25 @@ +--- +- name: Download Oh My Fish + git: + repo: "{{ omf_git_repo }}" + dest: "{{ workdir_path }}/omf" + become: yes + become_user: "{{ user }}" + +- name: Set user's default shell + user: + name: "{{ user }}" + shell: /usr/bin/fish + +- stat: + path: "{{ user_home }}/.local/share/omf" + register: omf_config_stat_result + +- name: Install Oh My Fish + shell: ./install --noninteractive + args: + executable: /usr/bin/fish + chdir: "{{ workdir_path }}/omf/bin/" + when: omf_config_stat_result.stat.exists == False + become: yes + become_user: "{{ user }}" diff --git a/Ansible/roles/base/tasks/main.yml b/Ansible/roles/base/tasks/main.yml new file mode 100644 index 0000000..75909b0 --- /dev/null +++ b/Ansible/roles/base/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: gather os specific variables + include_vars: "{{ item }}" + with_first_found: + - "../defaults/{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | int }}.yml" + - "../defaults/{{ ansible_distribution | lower }}.yml" + - "../defaults/{{ ansible_os_family | lower }}.yml" + - "../defaults/defaults.yml" + tags: variables + +- include_tasks: "{{ item }}" + with_first_found: + - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | int }}.yml" + - "{{ ansible_distribution | lower }}.yml" + - "{{ ansible_os_family | lower }}.yml" + - defaults.yml + +- name: Get passwd file + shell: grep -r "^{{ user }}" /etc/passwd + register: grep_user + failed_when: false + +- block: + - name: Apply common tasks + include_tasks: common.yml + + - name: Applying fish tasks + include_tasks: fish.yml + + when: grep_user.stdout diff --git a/Ansible/roles/base/tasks/ubuntu.yml b/Ansible/roles/base/tasks/ubuntu.yml new file mode 100644 index 0000000..4ffeb31 --- /dev/null +++ b/Ansible/roles/base/tasks/ubuntu.yml @@ -0,0 +1,5 @@ +--- +- name: Install Ubuntu packages + apt: + name: "{{ common_repo_package_list }}" + state: latest diff --git a/Ansible/roles/base/vars/main.yml b/Ansible/roles/base/vars/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/Ansible/roles/base/vars/main.yml @@ -0,0 +1 @@ +--- diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e129078 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2018, Elijah Lazkani +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7324600 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Solid State Subether +This is my personal repository for bootstrapping machines with [Ansible](https://www.ansible.com) for my own use. + +These types of repositories are generally called dotfile repositories. diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..05bd14f --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# This script will bootstrap the machine using Ansible +# Copyright (C) 2018 Elijah Lazkani + +playbook=$1 + +function _find_ansible() { + + command ansible-playbook -h > /dev/null 2>&1 + if [[ $? -ne 0 ]]; + then + echo "Ansible not found..." + exit 1 + fi +} + +function _ansible () { + + _find_ansible + + echo "Bootstrapping Ansible" + if [[ $playbook ]]; + then + if [ ! -f inventory ]; + then + echo "Inventory file not found" + touch inventory + fi + + echo "Sit down, relax and kick your legs up, fun is about to begin..." + ansible-playbook -i inventory Ansible/$playbook --ask-sudo-pass + else + echo "Choose a profile to run from the list below:" + find Ansible/ -maxdepth 1 -name "*.yml" -type f -printf " - %f\n" + fi +} + +_ansible diff --git a/requirements/development.txt b/requirements/development.txt new file mode 100644 index 0000000..2dd7021 --- /dev/null +++ b/requirements/development.txt @@ -0,0 +1,3 @@ +ansible +molecule +docker-py diff --git a/requirements/requirements.txt b/requirements/requirements.txt new file mode 100644 index 0000000..5ab2b3b --- /dev/null +++ b/requirements/requirements.txt @@ -0,0 +1,2 @@ +ansible +python-dnf