diff --git a/inventories/group_vars/pi.yml b/inventories/group_vars/pi.yml new file mode 100644 index 0000000..9fcd8c4 --- /dev/null +++ b/inventories/group_vars/pi.yml @@ -0,0 +1,9 @@ +--- +install_packages: + - vim + - bc + - netcat + - curl + - wget + - telnet +... diff --git a/inventories/group_vars/seboto.yml b/inventories/group_vars/seboto.yml new file mode 100644 index 0000000..9fcd8c4 --- /dev/null +++ b/inventories/group_vars/seboto.yml @@ -0,0 +1,9 @@ +--- +install_packages: + - vim + - bc + - netcat + - curl + - wget + - telnet +... diff --git a/playbooks/packages.yml b/playbooks/packages.yml new file mode 100644 index 0000000..08dd716 --- /dev/null +++ b/playbooks/packages.yml @@ -0,0 +1,7 @@ +--- +- name: Manage Packages + hosts: all + remote_user: root + roles: + - packages +... diff --git a/roles/packages/.travis.yml b/roles/packages/.travis.yml new file mode 100644 index 0000000..129928c --- /dev/null +++ b/roles/packages/.travis.yml @@ -0,0 +1,25 @@ +services: docker + +env: +- distro: centos7 +- distro: centos6 +- distro: fedora27 +- distro: ubuntu1710 +- distro: ubuntu1604 +- distro: ubuntu1404 + +script: + # Configure test script so we can run extra tests after playbook is run. + - export container_id=$(date +%s) + - export cleanup=false + + # Download test shim. + - wget -O ${PWD}/tests/test.sh https://gist.github.com/brentwg/64f90bdda32a51360f71558d3171fcbb/raw/ + - chmod +x ${PWD}/tests/test.sh + + # Run tests. + - ${PWD}/tests/test.sh + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ + diff --git a/roles/packages/README.md b/roles/packages/README.md new file mode 100644 index 0000000..3e79a26 --- /dev/null +++ b/roles/packages/README.md @@ -0,0 +1,47 @@ +# Ansible Role: Packages + +[![Build Status](https://travis-ci.org/brentwg/ansible-role-packages.svg?branch=master)](https://travis-ci.org/brentwg/ansible-role-packages) + +A simple Ansible role used to install, remove, and update distrobution base repository software packages. + +(No feature currently exists for enabling additional, third-party repositories.) + +## Requirements +Ansible minimum version: 2.4 + +## Role Variables +Available default values are listed below (See `defaults/main.yml`): +``` +# for software package updates +install_all_package_updates: true + +# list of packages to install +install_packages: [] + +# list of packages to remove +remove_packages: [] + +# list of packages to update +update_packages: [] + +``` +Set `install_all_package_updates` to `true` to enable the automated installation of all software package updates. Set it to `false` to disable all updates. + +`install_packages`, `remove_packages`, and `update_packages` expect to receive a list of package names that are specific to whichever Linux distribution you are running. + +**NOTE**: If you've already set `install_all_package_updates` to `true`, then there is naturally no requirement to redundantly list additional packages in `update_packages`; however, program logic would still allow this (since there is *probably* no harm done). +## Dependencies +None. + +## Example Playbook +``` +- hosts: all + + vars: + install_all_package_updates: true + install_packages: + - vim-enhanced + + roles: + - brentwg.packages +``` diff --git a/roles/packages/defaults/main.yml b/roles/packages/defaults/main.yml new file mode 100644 index 0000000..31334fc --- /dev/null +++ b/roles/packages/defaults/main.yml @@ -0,0 +1,13 @@ +--- +# for software package updates +install_all_package_updates: true + +# list of packages to install +install_packages: [] + +# list of packages to remove +remove_packages: [] + +# list of packages to update +update_packages: [] + diff --git a/roles/packages/meta/main.yml b/roles/packages/meta/main.yml new file mode 100644 index 0000000..1ef65cf --- /dev/null +++ b/roles/packages/meta/main.yml @@ -0,0 +1,28 @@ +--- +dependencies: [] + +galaxy_info: + author: brentwg + description: A simple Ansible role used to install and update software packages. + company: "None" + license: "None" + min_ansible_version: 2.4 + platforms: + - name: EL + versions: + - 6 + - 7 + - name: Fedora + versions: + - 26 + - name: Ubuntu + versions: + - artful + - xenial + - trusty + galaxy_tags: + - system + - packages + - install + - remove + - updates diff --git a/roles/packages/tasks/install-package-updates.yml b/roles/packages/tasks/install-package-updates.yml new file mode 100644 index 0000000..7fd27f8 --- /dev/null +++ b/roles/packages/tasks/install-package-updates.yml @@ -0,0 +1,21 @@ +--- +- name: "Working around an Ansible/Aptitude issue..." + apt: + pkg: aptitude + state: latest + become: true + when: ansible_os_family == 'Debian' + +- name: Install all software package updates + package: + name: "*" + state: "latest" + become: true + when: install_all_package_updates + +- name: Install specified software package updates + package: + name: "{{ item }}" + state: latest + become: true + with_items: "{{ update_packages }}" diff --git a/roles/packages/tasks/install-remove-packages.yml b/roles/packages/tasks/install-remove-packages.yml new file mode 100644 index 0000000..9bcc3bb --- /dev/null +++ b/roles/packages/tasks/install-remove-packages.yml @@ -0,0 +1,14 @@ +--- +- name: Install additional software packages + package: + name: "{{ item }}" + state: present + become: true + with_items: "{{ install_packages }}" + +- name: Remove specified software packages + package: + name: "{{ item }}" + state: absent + become: true + with_items: "{{ remove_packages }}" diff --git a/roles/packages/tasks/main.yml b/roles/packages/tasks/main.yml new file mode 100644 index 0000000..d4e2e09 --- /dev/null +++ b/roles/packages/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- import_tasks: install-package-updates.yml + +- import_tasks: install-remove-packages.yml diff --git a/roles/packages/tests/README.md b/roles/packages/tests/README.md new file mode 100644 index 0000000..095a919 --- /dev/null +++ b/roles/packages/tests/README.md @@ -0,0 +1,11 @@ +# Ansible Role tests + +To run the test playbook(s) in this directory: + + 1. Install and start Docker. + 1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`: +`wget -O tests/test.sh https://gist.github.com/brentwg/64f90bdda32a51360f71558d3171fcbb/raw/` + 1. Make the test shim executable: `chmod +x tests/test.sh`. + 1. Run (from the role's root directory) `distro=[distro] playbook=[playbook] ./tests/test.sh` + +If you **don't** want the container to be automatically deleted after the test playbook is run, then add the following environment variables: `cleanup=false container_id=$(date +%s)` \ No newline at end of file diff --git a/roles/packages/tests/test.yml b/roles/packages/tests/test.yml new file mode 100644 index 0000000..4089b84 --- /dev/null +++ b/roles/packages/tests/test.yml @@ -0,0 +1,11 @@ +--- +- hosts: all + + pre_tasks: + - name: Update apt cache. + apt: update_cache=yes cache_valid_time=600 + when: ansible_os_family == 'Debian' + changed_when: false + + roles: + - role_under_test