Refactor role to latest changes

Over the last 2 years we have learned a lot of things with ansible.
Bump this role to be inline with others.

This also import our role in to openstack-infra testing.

Change-Id: I63f9c936fae40e536699cd612c0505e0f3a72d5d
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2017-05-30 11:01:06 -04:00
parent ec7a080931
commit d9f73fee22
No known key found for this signature in database
GPG Key ID: 611A80832067AF38
13 changed files with 76 additions and 56 deletions

View File

@ -1,4 +1,4 @@
[gerrit] [gerrit]
host=review.openstack.org host=review.openstack.org
port=29418 port=29418
project=openstack/ansible-role-nodepool.git project=openstack/ansible-role-logrotate.git

10
bindep.txt Normal file
View File

@ -0,0 +1,10 @@
# This is a cross-platform list tracking distribution packages needed by tests;
# see http://docs.openstack.org/infra/bindep/ for additional information.
git
libffi-devel [platform:rpm]
libffi-dev [platform:dpkg]
libselinux-python [platform:rpm]
libssl-dev [platform:dpkg]
openssl-devel [platform:rpm]
python2-dnf [platform:fedora]

View File

@ -1,4 +1,4 @@
# Copyright 2015 Red Hat, Inc. # Copyright 2017 Red Hat, Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -12,6 +12,19 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
--- ---
# tasks/main.yaml
logrotate_task_manager:
- install
- config
# tasks/install.yaml
logrotate_install_method: package
logrotate_package_name: logrotate
logrotate_package_state: installed
# tasks/config.yaml
logrotate_configs: [] logrotate_configs: []
logrotate_template_logrotate_config_dest: /etc/logrotate.d logrotate_template_logrotate_config_dest: /etc/logrotate.d

View File

@ -1 +1 @@
ansible ansible>=2.0.0

View File

@ -12,11 +12,16 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
--- ---
- debug:
msg: "{{ item }}"
with_items: "{{ logrotate_configs }}"
- name: Template logrotate.d config files. - name: Template logrotate.d config files.
become: yes
template: template:
dest: "{{ logrotate_template_logrotate_config_dest }}/{{ item.name }}" dest: "{{ logrotate_template_logrotate_config_dest }}/{{ item.name }}"
group: root group: root
mode: 0644 mode: 0644
owner: root owner: root
src: "{{ logrotate_template_logrotate_config_src }}" src: "{{ logrotate_template_logrotate_config_src }}"
with_items: logrotate_configs with_items: "{{ logrotate_configs }}"

View File

@ -12,8 +12,4 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
--- ---
- include: install/debian.yaml - include: "install/{{ logrotate_install_method }}.yaml"
when: ansible_os_family == 'Debian'
- include: install/redhat.yaml
when: ansible_os_family == 'RedHat'

View File

@ -13,6 +13,7 @@
# under the License. # under the License.
--- ---
- name: Ensure logrotate is installed. - name: Ensure logrotate is installed.
apt: become: yes
pkg: logrotate package:
state: installed name: "{{ logrotate_package_name }}"
state: "{{ logrotate_package_state }}"

View File

@ -1,18 +0,0 @@
# Copyright 2015 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
---
- name: Ensure logrotate is installed.
yum:
pkg: logrotate
state: installed

View File

@ -12,8 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
--- ---
- include: install.yaml - include: "{{ logrotate_task }}.yaml"
sudo: yes with_items: "{{ logrotate_task_manager }}"
loop_control:
- include: config.yaml loop_var: logrotate_task
sudo: yes

View File

@ -1,2 +1,2 @@
[defaults] [defaults]
roles_path = .. roles_path = ../..

View File

@ -1,2 +1,2 @@
[all] [all]
localhost ansible_connection=local localhost ansible_connection=ssh

View File

@ -13,12 +13,22 @@
# under the License. # under the License.
--- ---
- hosts: localhost - hosts: localhost
sudo: yes
vars: vars:
rolename: "{{ lookup('pipe', 'pwd') | dirname | basename }}" rolename: "{{ lookup('pipe', 'pwd') | dirname | basename }}"
logrotate_configs:
- name: foo
log: /var/log/foo.log
options:
- compress
- missingok
- rotate 7
- daily
- notifempty
pre_tasks: pre_tasks:
# Make sure OS does not have a stale package cache. # Make sure OS does not have a stale package cache.
- name: Update apt cache. - name: Update apt cache.
become: yes
apt: apt:
update_cache: yes update_cache: yes
when: ansible_os_family == 'Debian' when: ansible_os_family == 'Debian'

40
tox.ini
View File

@ -1,27 +1,19 @@
[tox] [tox]
minversion = 1.4.2 minversion = 1.4.2
envlist = ansible-lint,docs,pep8 envlist = docs,linters
skipsdist = True skipsdist = True
[testenv] [testenv]
deps = -r{toxinidir}/requirements.txt deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt
[testenv:ansible-lint] [testenv:functional]
setenv =
ANSIBLE_CONFIG = tests/ansible.cfg
whitelist_externals = bash
commands = commands =
bash -c "find . -type f -regex '.*.y[a]?ml' -print0 | xargs -t -n1 -0 \ # NOTE(pabelanger): Because ansible default ansible_user to null now, we need to pass it via CLI.
ansible-lint" ansible-playbook -i tests/inventory tests/test.yaml -e ansible_user={env:USER}
bash -c "find tests -type f -regex '.*.y[a]?ml' -print | xargs -t -n1 \ passenv =
ansible-playbook --syntax-check -i tests/inventory \ HOME
-e rolename=$(basename $(pwd)) > /dev/null" USER
[testenv:ansible-functional]
commands =
ansible-playbook -i tests/inventory tests/test.yaml
passenv = HOME
setenv = setenv =
ANSIBLE_CONFIG = {toxinidir}/tests/ansible.cfg ANSIBLE_CONFIG = {toxinidir}/tests/ansible.cfg
PYTHONUNBUFFERED = 1 PYTHONUNBUFFERED = 1
@ -29,9 +21,6 @@ setenv =
[testenv:docs] [testenv:docs]
commands = python setup.py build_sphinx commands = python setup.py build_sphinx
[testenv:pep8]
commands = flake8
[testenv:venv] [testenv:venv]
commands = {posargs} commands = {posargs}
@ -42,3 +31,18 @@ show-source = True
ignore = E123,E125 ignore = E123,E125
builtins = _ builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build
[testenv:linters]
setenv =
ANSIBLE_CONFIG = tests/ansible.cfg
whitelist_externals = bash
commands =
# PEP8 Lint Check
flake8
# Ansible Lint Check
bash -c "find . -type f -regex '.*.y[a]?ml' -print0 | xargs -t -n1 -0 \
ansible-lint"
# Ansible Syntax Check
bash -c "find tests -type f -regex '.*.y[a]?ml' -print | xargs -t -n1 \
ansible-playbook --syntax-check -i tests/inventory \
-e rolename=$(basename $(pwd)) > /dev/null"