Added package role

This commit is contained in:
Jens Heinitz 2021-11-13 14:33:05 +01:00
parent ba9d94fe69
commit 0de8837ac7
12 changed files with 199 additions and 0 deletions

View File

@ -0,0 +1,9 @@
---
install_packages:
- vim
- bc
- netcat
- curl
- wget
- telnet
...

View File

@ -0,0 +1,9 @@
---
install_packages:
- vim
- bc
- netcat
- curl
- wget
- telnet
...

7
playbooks/packages.yml Normal file
View File

@ -0,0 +1,7 @@
---
- name: Manage Packages
hosts: all
remote_user: root
roles:
- packages
...

View File

@ -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/

47
roles/packages/README.md Normal file
View File

@ -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
```

View File

@ -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: []

View File

@ -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

View File

@ -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 }}"

View File

@ -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 }}"

View File

@ -0,0 +1,4 @@
---
- import_tasks: install-package-updates.yml
- import_tasks: install-remove-packages.yml

View File

@ -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)`

View File

@ -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