Initial commit

This commit is contained in:
Sam Doran 2018-04-23 12:04:58 -04:00
commit c732b72ce5
9 changed files with 168 additions and 0 deletions

80
README.md Normal file
View File

@ -0,0 +1,80 @@
OpenStack Operations
=========
Perform various common OpenStack operations by calling this role with an action and appropriate variables.
Requirements
------------
None
Role Variables
--------------
**General Variables**
| Name | Default Value | Description |
|-------------------|---------------------|----------------------|
| `operations_task` | `skip` | Task file to include and run. See `tasks/` for available options. |
**Variables used for cleaning up Docker**
| Name | Default Value | Description |
|-------------------|---------------------|----------------------|
| `operations_docker_bin` | `docker` | Path to `docker` binary. |
| `operations_docker_cleanup` | [see `defaults/main.yml`] | Filters used to determine which items will be removed. Uses Docker filter syntax. See Docker guides for [images](https://docs.docker.com/engine/reference/commandline/images/#filtering), [containers](https://docs.docker.com/engine/reference/commandline/ps/#filtering), and [volumes](https://docs.docker.com/engine/reference/commandline/volume_ls/#filtering) for filter options. |
**Variables for fetching logs**
| Name | Default Value | Description |
|-------------------|---------------------|----------------------|
| `operations_log_destination` | `{{ playbook_dir }}` | Path where logs will be stored when fetched from remote systems. |
**Variables for restarting services**
| Name | Default Value | Description |
|-------------------|---------------------|----------------------|
| `operations_service_names` | `[]` | List of services to restart on target systems. |
Dependencies
------------
None
Example Playbook
----------------
- hosts: all
tasks:
- name: Restart a service
import_role:
name: openstack-operations
vars:
operations_task: restart_service
operations_service_list:
- docker
- keystone
- mariadb
- name: Cleanup unused Docker images
import_role:
name: openstack-operations
vars:
operations_task: cleanup_images
- name: Fetch logs
import_role:
name: openstack-operations
vars:
operations_task: fetch_logs
- name: List running services
import_role:
name: list_services
vars:
operations_task: fetch_logs
License
-------
Apache 2.0

21
defaults/main.yml Normal file
View File

@ -0,0 +1,21 @@
operations_operation: skip
# Cleanup Docker
operations_docker_bin: docker
operations_docker_cleanup:
image_filters:
- dangling=true
volume_filters:
- dangling=true
container_filters:
- status=exited
- status=dead
# Fetch Logs
operations_log_destination: "{{ playbook_dir }}"
# Restart Service
operations_service_names: []

0
handlers/main.yml Normal file
View File

17
meta/main.yml Normal file
View File

@ -0,0 +1,17 @@
galaxy_info:
author: Sam Doran
description: "Perform common OpenStack operations"
company: Ansible by Red Hat
license: Apache 2.0
min_ansible_version: 2.4
platforms:
- name: EL
versions:
- 7
galaxy_tags:
- openstack
- cloud
dependencies: []

29
tasks/cleanup_images.yml Normal file
View File

@ -0,0 +1,29 @@
- name: List filtered images
command: '{{ operations_docker_bin }} images {% for filter in operations_docker_cleanup.image_filters %}-f {{ filter }} {% endfor %}-q'
changed_when: no
check_mode: no
register: _dangling_images
- name: Remove images
command: '{{ operations_docker_bin }} rmi {{ item }}'
with_items: "{{ _dangling_images.stdout_lines }}"
- name: List filtered containers
command: '{{ operations_docker_bin }} ps {% for filter in operations_docker_cleanup.container_filters %}-f {{ filter }} {% endfor %} -q'
changed_when: no
check_mode: no
register: _dead_containers
- name: Remove containers
command: '{{ operations_docker_bin }} rm {{ item }}'
with_items: "{{ _dead_containers.stdout_lines }}"
- name: List filtered volumes
command: '{{ operations_docker_bin }} volume ls {% for filter in operations_docker_cleanup.volume_filters %}-f {{ filter }} {% endfor %} -q'
changed_when: no
check_mode: no
register: _dangling_volumes
- name: Remove dangling volumes
command: "{{ operations_docker_bin }} volume rm {{ item }}"
with_items: "{{ _dangling_volumes }}"

18
tasks/fetch_logs.yml Normal file
View File

@ -0,0 +1,18 @@
- name: Find logs
find:
age: "{{ operations_logs.age | default(omit) }}"
contains: "{{ operations_logs.contains | default(omit) }}"
file_type: "{{ operations_logs.file_type | default(omit) }}"
follow: "{{ operations_logs.follow | default(omit) }}"
paths: "{{ operations_logs.paths | default('/var/log') }}"
patterns: "{{ operations_logs.patterns | default('*.log') }}"
recurse: "{{ operations_logs.recurse | default('yes') }}"
size: "{{ operations_logs.size | default(omit) }}"
use_regex: "{{ operations_logs.use_regex | default(omit) }}"
register: _logs
- name: Fetch logs and place in {{ operations_log_destination }}
fetch:
src: "{{ item.path }}"
dest: "{{ operations_log_destination }}/{{ inventory_hostname }}"
with_items: "{{ _logs.files }}"

3
tasks/main.yml Normal file
View File

@ -0,0 +1,3 @@
- include_tasks: "{{ operations_task }}.yml"
tags:
- operations

View File

0
tasks/skip.yml Normal file
View File