From d1549559db474cd9c78bc67e86590a404e4721ec Mon Sep 17 00:00:00 2001 From: John Freeman Date: Sun, 26 Aug 2018 15:22:30 +0100 Subject: [PATCH] Implemented ctop role (#1) Role to download and install ctop. --- .travis.yml | 93 +++++++++++++++++ .yamllint | 2 +- README.md | 139 ++++++++++++++++++++++--- defaults/main.yml | 9 +- handlers/main.yml | 2 +- meta/main.yml | 82 +++++---------- molecule/centos/Dockerfile.j2 | 14 +++ molecule/centos/INSTALL.rst | 26 +++++ molecule/centos/molecule.yml | 29 ++++++ molecule/debian_max/Dockerfile.j2 | 14 +++ molecule/debian_max/INSTALL.rst | 26 +++++ molecule/debian_max/molecule.yml | 29 ++++++ molecule/debian_min/Dockerfile.j2 | 14 +++ molecule/debian_min/INSTALL.rst | 26 +++++ molecule/debian_min/molecule.yml | 29 ++++++ molecule/default/molecule.yml | 10 +- molecule/default/tests/test_default.py | 14 --- molecule/default/tests/test_role.py | 30 ++++++ molecule/fedora/Dockerfile.j2 | 14 +++ molecule/fedora/INSTALL.rst | 26 +++++ molecule/fedora/molecule.yml | 29 ++++++ molecule/opensuse/Dockerfile.j2 | 14 +++ molecule/opensuse/INSTALL.rst | 26 +++++ molecule/opensuse/molecule.yml | 29 ++++++ molecule/ubuntu_max/Dockerfile.j2 | 14 +++ molecule/ubuntu_max/INSTALL.rst | 26 +++++ molecule/ubuntu_max/molecule.yml | 29 ++++++ molecule/ubuntu_min/Dockerfile.j2 | 14 +++ molecule/ubuntu_min/INSTALL.rst | 26 +++++ molecule/ubuntu_min/molecule.yml | 29 ++++++ tasks/main.yml | 31 +++++- tests/inventory | 2 - tests/test.yml | 5 - vars/main.yml | 18 +++- 34 files changed, 823 insertions(+), 97 deletions(-) create mode 100644 .travis.yml create mode 100644 molecule/centos/Dockerfile.j2 create mode 100644 molecule/centos/INSTALL.rst create mode 100644 molecule/centos/molecule.yml create mode 100644 molecule/debian_max/Dockerfile.j2 create mode 100644 molecule/debian_max/INSTALL.rst create mode 100644 molecule/debian_max/molecule.yml create mode 100644 molecule/debian_min/Dockerfile.j2 create mode 100644 molecule/debian_min/INSTALL.rst create mode 100644 molecule/debian_min/molecule.yml delete mode 100644 molecule/default/tests/test_default.py create mode 100644 molecule/default/tests/test_role.py create mode 100644 molecule/fedora/Dockerfile.j2 create mode 100644 molecule/fedora/INSTALL.rst create mode 100644 molecule/fedora/molecule.yml create mode 100644 molecule/opensuse/Dockerfile.j2 create mode 100644 molecule/opensuse/INSTALL.rst create mode 100644 molecule/opensuse/molecule.yml create mode 100644 molecule/ubuntu_max/Dockerfile.j2 create mode 100644 molecule/ubuntu_max/INSTALL.rst create mode 100644 molecule/ubuntu_max/molecule.yml create mode 100644 molecule/ubuntu_min/Dockerfile.j2 create mode 100644 molecule/ubuntu_min/INSTALL.rst create mode 100644 molecule/ubuntu_min/molecule.yml delete mode 100644 tests/inventory delete mode 100644 tests/test.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..387c465 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,93 @@ +--- +language: python +python: '2.7' + +# Spin off separate builds for each of the following versions +# of Ansible and Linux. +matrix: + include: + - env: + - ANSIBLE_VERSION=2.4.6 + - MOLECULE_SCENARIO=centos + - env: + - ANSIBLE_VERSION=2.4.6 + - MOLECULE_SCENARIO=debian_max + - env: + - ANSIBLE_VERSION=2.4.6 + - MOLECULE_SCENARIO=debian_min + - env: + - ANSIBLE_VERSION=2.4.6 + - MOLECULE_SCENARIO=ubuntu_max + - env: + - ANSIBLE_VERSION=2.4.6 + - MOLECULE_SCENARIO=ubuntu_min + - env: + - ANSIBLE_VERSION=2.4.6 + - MOLECULE_SCENARIO=opensuse + - env: + - ANSIBLE_VERSION=2.6.3 + - MOLECULE_SCENARIO=centos + - env: + - ANSIBLE_VERSION=2.6.3 + - MOLECULE_SCENARIO=debian_max + - env: + - ANSIBLE_VERSION=2.6.3 + - MOLECULE_SCENARIO=debian_min + - env: + - ANSIBLE_VERSION=2.6.3 + - MOLECULE_SCENARIO=ubuntu_max + - env: + - ANSIBLE_VERSION=2.6.3 + - MOLECULE_SCENARIO=ubuntu_min + - env: + - ANSIBLE_VERSION=2.6.3 + - MOLECULE_SCENARIO=opensuse + +# Require the standard build environment +sudo: required + +# Require Ubuntu 14.04 +dist: trusty + +# Require Docker +services: + - docker + +# Cache Ansible and Molecule to speed things up +cache: + - pip + +before_install: + - sudo apt-get -qq update + - sudo apt-get install -o Dpkg::Options::='--force-confold' --force-yes -y docker-ce + +install: + # Install Ansible + - pip install "ansible~=$ANSIBLE_VERSION" + + # Install Python Docker library + - pip install docker + + # Install Molecule + - pip install 'molecule==2.17.0' + + # Check Ansible version + - ansible --version + + # Check Molecule version + - molecule --version + + # Build the Docker images + - molecule create --scenario-name=$MOLECULE_SCENARIO + - molecule destroy --scenario-name=$MOLECULE_SCENARIO + +script: + - molecule test --scenario-name=$MOLECULE_SCENARIO + +branches: + only: + - master + - /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([\.\-].*)?$/ + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/.yamllint b/.yamllint index 3a2255e..77be3fb 100644 --- a/.yamllint +++ b/.yamllint @@ -10,4 +10,4 @@ rules: line-length: disable # NOTE(retr0h): Templates no longer fail this lint rule. # Uncomment if running old Molecule templates. - # truthy: disable + truthy: disable diff --git a/README.md b/README.md index 225dd44..4e3e417 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,149 @@ -Role Name -========= +Ansible Role: ctop +====================== -A brief description of the role goes here. +[![Build Status](https://travis-ci.com/gantsign/ansible_role_ctop.svg?branch=master)](https://travis-ci.com/gantsign/ansible_role_ctop) +[![Ansible Galaxy](https://img.shields.io/badge/ansible--galaxy-gantsign.ctop-blue.svg)](https://galaxy.ansible.com/gantsign/ctop) +[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/gantsign/ansible_role_ctop/master/LICENSE) + +Role to download and install [ctop](https://ctop.sh) the top-like interface for +container metrics. View CPU, RAM and network I/O for your Docker containers at +a glance from your terminal. Requirements ------------ -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. +* Ansible >= 2.4 + +* Linux Distribution + + * Debian Family + + * Debian + + * Jessie (8) + * Stretch (9) + + * Ubuntu + + * Trusty (14.04) + * Xenial (16.04) + * Bionic (18.04) + + * RedHat Family + + * CentOS + + * 7 + + * Fedora + + * 28 + + * SUSE Family + + * OpenSUSE + + * 42.2 + + * Note: other versions are likely to work but have not been tested. + +* Docker (already installed) Role Variables -------------- -A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. +The following variables will change the behavior of this role (default values +are shown below): -Dependencies ------------- +```yaml +# ctop version number +ctop_version: '0.7.1' -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. +# SHA256 sum for the ctop redistributable +ctop_redis_sha256sum: '38cfd92618ba2d92e0e1262c0c43d7690074b4b8dc77844b654f8e565166b577' + +# Directory to store files downloaded for ctop +ctop_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}" +``` Example Playbook ---------------- -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: +```yaml +- hosts: servers + roles: + - role: gantsign.ctop +``` - - hosts: servers - roles: - - { role: username.rolename, x: 42 } +Tab Completion for Zsh +---------------------- + +### Using Ansible + +We recommend using the +[gantsign.antigen](https://galaxy.ansible.com/gantsign/antigen) role to enable +tab completion for ctop (this must be configured for each user). + +```yaml +- hosts: servers + roles: + - role: gantsign.ctop + + - role: gantsign.antigen + users: + - username: example + antigen_bundles: + - name: ctop + url: gantsign/zsh-plugins + location: ctop +``` + +### Using Antigen + +If you prefer to use [Antigen](https://github.com/zsh-users/antigen) directly +add the following to your Antigen configuration: + +```bash +antigen bundle gantsign/zsh-plugins ctop +``` + +More Roles From GantSign +------------------------ + +You can find more roles from GantSign on +[Ansible Galaxy](https://galaxy.ansible.com/gantsign). + +Development & Testing +--------------------- + +This project uses [Molecule](http://molecule.readthedocs.io/) to aid in the +development and testing; the role is unit tested using +[Testinfra](http://testinfra.readthedocs.io/) and +[pytest](http://docs.pytest.org/). + +To develop or test you'll need to have installed the following: + +* Linux (e.g. [Ubuntu](http://www.ubuntu.com/)) +* [Docker](https://www.docker.com/) +* [Python](https://www.python.org/) (including python-pip) +* [Ansible](https://www.ansible.com/) +* [Molecule](http://molecule.readthedocs.io/) + +To test this role run the following command from the project root: + +```bash +molecule test +``` License ------- -BSD +MIT Author Information ------------------ -An optional section for the role authors to include contact information, or a website (HTML is not allowed). +John Freeman + +GantSign Ltd. +Company No. 06109112 (registered in England) diff --git a/defaults/main.yml b/defaults/main.yml index bde713b..3951514 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,9 @@ --- -# defaults file for ansible_role_ctop \ No newline at end of file +# ctop version number +ctop_version: '0.7.1' + +# SHA256 sum for the ctop redistributable +ctop_redis_sha256sum: '38cfd92618ba2d92e0e1262c0c43d7690074b4b8dc77844b654f8e565166b577' + +# Directory to store files downloaded for ctop +ctop_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}" diff --git a/handlers/main.yml b/handlers/main.yml index 3f67b34..5b6f86c 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,2 @@ --- -# handlers file for ansible_role_ctop \ No newline at end of file +# handlers file for ansible_role_ctop diff --git a/meta/main.yml b/meta/main.yml index 7223799..90ef5a3 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,57 +1,29 @@ +--- galaxy_info: - author: your name - description: your description - company: your company (optional) - - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value - # issue_tracker_url: http://example.com/issue/tracker - - # Some suggested licenses: - # - BSD (default) - # - MIT - # - GPLv2 - # - GPLv3 - # - Apache - # - CC-BY - license: license (GPLv2, CC-BY, etc) - - min_ansible_version: 1.2 - - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - - # Optionally specify the branch Galaxy will use when accessing the GitHub - # repo for this role. During role install, if no tags are available, - # Galaxy will use this branch. During import Galaxy will access files on - # this branch. If Travis integration is configured, only notifications for this - # branch will be accepted. Otherwise, in all cases, the repo's default branch - # (usually master) will be used. - #github_branch: - - # - # platforms is a list of platforms, and each platform has a name and a list of versions. - # - # platforms: - # - name: Fedora - # versions: - # - all - # - 25 - # - name: SomePlatform - # versions: - # - all - # - 1.0 - # - 7 - # - 99.99 - - galaxy_tags: [] - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. - + author: John Freeman + role_name: ctop + description: Ansible role for downloading and installing ctop. + company: GantSign Ltd. + license: MIT + min_ansible_version: 2.4 + platforms: + - name: EL + versions: + - 7 + - name: Fedora + versions: + - 28 + - name: Ubuntu + versions: + - trusty + - xenial + - bionic + - name: Debian + versions: + - jessie + - stretch + galaxy_tags: + - ctop + - docker + - development dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. \ No newline at end of file diff --git a/molecule/centos/Dockerfile.j2 b/molecule/centos/Dockerfile.j2 new file mode 100644 index 0000000..19692c2 --- /dev/null +++ b/molecule/centos/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/molecule/centos/INSTALL.rst b/molecule/centos/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/centos/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/centos/molecule.yml b/molecule/centos/molecule.yml new file mode 100644 index 0000000..eb67175 --- /dev/null +++ b/molecule/centos/molecule.yml @@ -0,0 +1,29 @@ +--- +dependency: + name: galaxy + +driver: + name: docker + +lint: + name: yamllint + +platforms: + - name: ansible_role_ctop_centos + image: centos:7 + +provisioner: + name: ansible + playbooks: + converge: ../default/playbook.yml + lint: + name: ansible-lint + +scenario: + name: centos + +verifier: + name: testinfra + directory: ../default/tests + lint: + name: flake8 diff --git a/molecule/debian_max/Dockerfile.j2 b/molecule/debian_max/Dockerfile.j2 new file mode 100644 index 0000000..19692c2 --- /dev/null +++ b/molecule/debian_max/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/molecule/debian_max/INSTALL.rst b/molecule/debian_max/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/debian_max/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/debian_max/molecule.yml b/molecule/debian_max/molecule.yml new file mode 100644 index 0000000..55a845f --- /dev/null +++ b/molecule/debian_max/molecule.yml @@ -0,0 +1,29 @@ +--- +dependency: + name: galaxy + +driver: + name: docker + +lint: + name: yamllint + +platforms: + - name: ansible_role_ctop_debian_max + image: debian:9 + +provisioner: + name: ansible + playbooks: + converge: ../default/playbook.yml + lint: + name: ansible-lint + +scenario: + name: debian_max + +verifier: + name: testinfra + directory: ../default/tests + lint: + name: flake8 diff --git a/molecule/debian_min/Dockerfile.j2 b/molecule/debian_min/Dockerfile.j2 new file mode 100644 index 0000000..19692c2 --- /dev/null +++ b/molecule/debian_min/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/molecule/debian_min/INSTALL.rst b/molecule/debian_min/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/debian_min/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/debian_min/molecule.yml b/molecule/debian_min/molecule.yml new file mode 100644 index 0000000..bbc24b3 --- /dev/null +++ b/molecule/debian_min/molecule.yml @@ -0,0 +1,29 @@ +--- +dependency: + name: galaxy + +driver: + name: docker + +lint: + name: yamllint + +platforms: + - name: ansible_role_ctop_debian_min + image: debian:8 + +provisioner: + name: ansible + playbooks: + converge: ../default/playbook.yml + lint: + name: ansible-lint + +scenario: + name: debian_min + +verifier: + name: testinfra + directory: ../default/tests + lint: + name: flake8 diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index f5e3b11..caa58a7 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -1,19 +1,25 @@ --- dependency: name: galaxy + driver: name: docker + lint: name: yamllint + platforms: - - name: instance - image: centos:7 + - name: ansible_role_ctop_default + image: ubuntu:18.04 + provisioner: name: ansible lint: name: ansible-lint + scenario: name: default + verifier: name: testinfra lint: diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py deleted file mode 100644 index eedd64a..0000000 --- a/molecule/default/tests/test_default.py +++ /dev/null @@ -1,14 +0,0 @@ -import os - -import testinfra.utils.ansible_runner - -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') - - -def test_hosts_file(host): - f = host.file('/etc/hosts') - - assert f.exists - assert f.user == 'root' - assert f.group == 'root' diff --git a/molecule/default/tests/test_role.py b/molecule/default/tests/test_role.py new file mode 100644 index 0000000..8eede6b --- /dev/null +++ b/molecule/default/tests/test_role.py @@ -0,0 +1,30 @@ +import os + +import testinfra.utils.ansible_runner + +import re + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_dir(host): + dir = host.file('/usr/local/bin') + assert dir.exists + assert dir.is_directory + assert dir.user == 'root' + assert dir.group == 'root' + + +def test_file(host): + installed_file = host.file('/usr/local/bin/ctop') + assert installed_file.exists + assert installed_file.is_file + assert installed_file.user == 'root' + assert installed_file.group == 'root' + + +def test_version(host): + version = host.check_output('ctop -v') + pattern = 'ctop version [0-9\\.]+' + assert re.search(pattern, version) diff --git a/molecule/fedora/Dockerfile.j2 b/molecule/fedora/Dockerfile.j2 new file mode 100644 index 0000000..19692c2 --- /dev/null +++ b/molecule/fedora/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/molecule/fedora/INSTALL.rst b/molecule/fedora/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/fedora/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/fedora/molecule.yml b/molecule/fedora/molecule.yml new file mode 100644 index 0000000..a7a1e16 --- /dev/null +++ b/molecule/fedora/molecule.yml @@ -0,0 +1,29 @@ +--- +dependency: + name: galaxy + +driver: + name: docker + +lint: + name: yamllint + +platforms: + - name: ansible_role_ctop_fedora + image: fedora:28 + +provisioner: + name: ansible + playbooks: + converge: ../default/playbook.yml + lint: + name: ansible-lint + +scenario: + name: fedora + +verifier: + name: testinfra + directory: ../default/tests + lint: + name: flake8 diff --git a/molecule/opensuse/Dockerfile.j2 b/molecule/opensuse/Dockerfile.j2 new file mode 100644 index 0000000..19692c2 --- /dev/null +++ b/molecule/opensuse/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/molecule/opensuse/INSTALL.rst b/molecule/opensuse/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/opensuse/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/opensuse/molecule.yml b/molecule/opensuse/molecule.yml new file mode 100644 index 0000000..5b47b35 --- /dev/null +++ b/molecule/opensuse/molecule.yml @@ -0,0 +1,29 @@ +--- +dependency: + name: galaxy + +driver: + name: docker + +lint: + name: yamllint + +platforms: + - name: ansible_role_ctop_opensuse + image: opensuse:42.2 + +provisioner: + name: ansible + playbooks: + converge: ../default/playbook.yml + lint: + name: ansible-lint + +scenario: + name: opensuse + +verifier: + name: testinfra + directory: ../default/tests + lint: + name: flake8 diff --git a/molecule/ubuntu_max/Dockerfile.j2 b/molecule/ubuntu_max/Dockerfile.j2 new file mode 100644 index 0000000..19692c2 --- /dev/null +++ b/molecule/ubuntu_max/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/molecule/ubuntu_max/INSTALL.rst b/molecule/ubuntu_max/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/ubuntu_max/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/ubuntu_max/molecule.yml b/molecule/ubuntu_max/molecule.yml new file mode 100644 index 0000000..4c4ece3 --- /dev/null +++ b/molecule/ubuntu_max/molecule.yml @@ -0,0 +1,29 @@ +--- +dependency: + name: galaxy + +driver: + name: docker + +lint: + name: yamllint + +platforms: + - name: ansible_role_ctop_ubuntu_max + image: ubuntu:18.04 + +provisioner: + name: ansible + playbooks: + converge: ../default/playbook.yml + lint: + name: ansible-lint + +scenario: + name: ubuntu_max + +verifier: + name: testinfra + directory: ../default/tests + lint: + name: flake8 diff --git a/molecule/ubuntu_min/Dockerfile.j2 b/molecule/ubuntu_min/Dockerfile.j2 new file mode 100644 index 0000000..19692c2 --- /dev/null +++ b/molecule/ubuntu_min/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/molecule/ubuntu_min/INSTALL.rst b/molecule/ubuntu_min/INSTALL.rst new file mode 100644 index 0000000..3904805 --- /dev/null +++ b/molecule/ubuntu_min/INSTALL.rst @@ -0,0 +1,26 @@ +******* +Docker driver installation guide +******* + +Requirements +============ + +* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html) +* Docker Engine +* docker-py +* docker + +Install +======= + +Ansible < 2.6 + +.. code-block:: bash + + $ sudo pip install docker-py + +Ansible >= 2.6 + +.. code-block:: bash + + $ sudo pip install docker diff --git a/molecule/ubuntu_min/molecule.yml b/molecule/ubuntu_min/molecule.yml new file mode 100644 index 0000000..660c24c --- /dev/null +++ b/molecule/ubuntu_min/molecule.yml @@ -0,0 +1,29 @@ +--- +dependency: + name: galaxy + +driver: + name: docker + +lint: + name: yamllint + +platforms: + - name: ansible_role_ctop_ubuntu_min + image: ubuntu:14.04 + +provisioner: + name: ansible + playbooks: + converge: ../default/playbook.yml + lint: + name: ansible-lint + +scenario: + name: ubuntu_min + +verifier: + name: testinfra + directory: ../default/tests + lint: + name: flake8 diff --git a/tasks/main.yml b/tasks/main.yml index ca9568b..d14549c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,31 @@ --- -# tasks file for ansible_role_ctop \ No newline at end of file +- name: create download directory + file: + state: directory + mode: 'u=rwx,go=rx' + dest: '{{ ctop_download_dir }}' + +- name: download ctop + get_url: + url: '{{ ctop_mirror }}/{{ ctop_redis_filename }}' + dest: '{{ ctop_download_dir }}/{{ ctop_redis_filename }}' + checksum: 'sha256:{{ ctop_redis_sha256sum }}' + mode: 'u=rw,go=r' + +- name: create the ctop installation dir + become: yes + file: + state: directory + owner: root + group: root + mode: 'u=rwx,go=rx' + dest: '{{ ctop_install_dir }}' + +- name: install ctop + become: yes + copy: + src: '{{ ctop_download_dir }}/{{ ctop_redis_filename }}' + remote_src: yes + dest: '{{ ctop_install_path }}' + force: yes + mode: 'u=rwx,go=rx' diff --git a/tests/inventory b/tests/inventory deleted file mode 100644 index 878877b..0000000 --- a/tests/inventory +++ /dev/null @@ -1,2 +0,0 @@ -localhost - diff --git a/tests/test.yml b/tests/test.yml deleted file mode 100644 index 8262328..0000000 --- a/tests/test.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- hosts: localhost - remote_user: root - roles: - - ansible_role_ctop \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml index 7d5a12b..1afc4ee 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,18 @@ --- -# vars file for ansible_role_ctop \ No newline at end of file +# Dir where ctop should be installed +ctop_install_dir: '/usr/local/bin' + +# Path where ctop should be installed +ctop_install_path: '{{ ctop_install_dir }}/ctop' + +# Mirror to download the ctop from +ctop_mirror: 'https://github.com/bcicen/ctop/releases/download/v{{ ctop_version }}' + +# The OS of the ctop redistributable +ctop_os: 'linux' + +# The CPU architecture of the ctop redistributable +ctop_architecture: 'amd64' + +# File name of the ctop redistributable file +ctop_redis_filename: 'ctop-{{ ctop_version }}-{{ ctop_os }}-{{ ctop_architecture }}'