Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lotusnoir committed Sep 24, 2020
0 parents commit bd37a58
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
skip_list:
- '106'
- '401'
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
language: python3.6
cache: pip
services: docker

env:
global:
- ROLE_NAME: apps_squid_exporter
matrix:
- MOLECULE_DISTRO: ubuntu2004
- MOLECULE_DISTRO: ubuntu1804
- MOLECULE_DISTRO: debian10

before_install:
# Upgrade Docker to work with docker-py.
- curl https://gist.githubusercontent.com/geerlingguy/ce883ad4aec6a5f1187ef93bd338511e/raw/36612d28981d92863f839c5aefe5b7dd7193d6c6/travis-ci-docker-upgrade.sh | sudo bash

install:
# Install test dependencies.
- pip install molecule yamllint ansible-lint docker molecule-goss

before_script:
# To use the role without the ansible github flag
- cd ../
- mv ansible-$ROLE_NAME $ROLE_NAME
- cd $ROLE_NAME

script:
# Run tests.
- molecule test
16 changes: 16 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
# Based on ansible-lint config
extends: default

rules:
colons:
max-spaces-after: -1
level: error
indentation: enable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: enable
new-lines:
type: unix
trailing-spaces: enable
truthy: enable
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017-2018 Pawel Krupa, Roman Demachkovych

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Ansible Role: ansible-apps_squid_exporter

## Description

[![Build Status](https://travis-ci.com/lotusnoir/ansible-apps_squid_exporter.svg?branch=master)](https://travis-ci.com/lotusnoir/ansible-apps_squid_exporter)[![License](https://img.shields.io/badge/license-MIT%20License-brightgreen.svg)](https://opensource.org/licenses/MIT)[![Ansible Role](https://img.shields.io/badge/ansible%20role-apps__squid_exporter-blue)](https://galaxy.ansible.com/lotusnoir/ansible-apps_squid_exporter/)[![GitHub tag](https://img.shields.io/badge/version-latest-blue)](https://github.com/lotusnoir/ansible-apps_squid_exporter/tags)

Deploy [squid_exporter](https://github.com/boynux/squid-exporter) to expose squid metrics to prometheus.

## Role variables

| Name | Default Value | Description |
| -------------- | ------------- | -----------------------------------|
| `squid_exporter_version` | 1.9.1 | squid_exporter version |
| `squid_exporter_squid_host` | localhost | hostname or ip of the squid server |
| `squid_exporter_squid_port` | 3128 | port of the squid service on the squid server |
| `squid_exporter_listen_port` | 9103 | port to expose prometheus metrics |

## Examples

---
- hosts: apps_squid_exporter
become: yes
become_method: sudo
gather_facts: yes
roles:
- role: ansible-apps_squid_exporter
environment:
http_proxy: "{{ http_proxy }}"
https_proxy: "{{ https_proxy }}"
no_proxy: "{{ no_proxy }}

## License

This project is licensed under MIT License. See [LICENSE](/LICENSE) for more details.
6 changes: 6 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
squid_exporter_version: "1.9.1"
squid_exporter_url: "https://github.com/boynux/squid-exporter/releases/download/v{{ squid_exporter_version }}/squid-exporter"
squid_exporter_squid_host: localhost
squid_exporter_squid_port: 3128
squid_exporter_listen_port: "9103"
5 changes: 5 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: "restart squid_exporter"
service:
name: "squid_exporter"
state: "restarted"
22 changes: 22 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
galaxy_info:
author: "Philippe leal"
description: "Install and configure squid exporter metrics for prometheus"
role_name: apps_squid_exporter
license: "GNU General Public License v3.0"
min_ansible_version: 2.8

platforms:
- name: "Ubuntu"
versions:
- "focal"
- name: "Debian"
versions:
- "buster"

galaxy_tags:
- squid
- exporter
- prometheus

dependencies: []
13 changes: 13 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Converge
hosts: all
become: true

pre_tasks:
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'
changed_when: false

roles:
- role: apps_squid_exporter
40 changes: 40 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
dependency:
name: galaxy

driver:
name: docker

lint: |
yamllint .
platforms:
- name: test-01.dvlp.example.com
image: "geerlingguy/docker-${MOLECULE_DISTRO:-debian10}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true

provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
lint: |
ansible-lint
scenario:
name: default
test_sequence:
- destroy
- dependency
- lint
- syntax
- create
- converge
# - verify
- destroy

verifier:
name: goss
29 changes: 29 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
- name: "Check for squid_exporter binary"
stat:
path: "/usr/local/bin/squid_exporter"
changed_when: false
register: squid_exporter_install

- when: not squid_exporter_install.stat.exists
block:
- name: "Download squid_exporter..."
get_url:
url: '{{ squid_exporter_url }}'
dest: /usr/local/bin/
timeout: 120
mode: 0755

- name: "Create systemd for squid_exporter"
template:
src: squid_exporter.service
dest: /etc/systemd/system/
mode: '0644'
notify: "restart squid_exporter"

- name: "Enable and Start squid_exporter.service"
systemd:
name: squid_exporter
state: started
enabled: true
daemon_reload: true
18 changes: 18 additions & 0 deletions templates/squid_exporter.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{ ansible_managed | comment }}

[Unit]
Description=Prometheus squid Exporter
After=network-online.target
StartLimitInterval=0

[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/squid-exporter -squid-hostname "{{ squid_exporter_squid_host }}" -squid-port {{ squid_exporter_squid_port }} -listen ":{{ squid_exporter_listen_port }}"
ExecReload=/bin/kill -HUP $MAINPID
SyslogIdentifier=squid_exporter
RestartSec=1
PrivateTmp=yes

[Install]
WantedBy=multi-user.target

0 comments on commit bd37a58

Please sign in to comment.