diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f56f5b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.retry +*/__pycache__ +*.pyc diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6df85e2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +--- +language: python +services: docker + +env: + global: + - ROLE_NAME: consul + +install: + - pip install -r requirements.txt + +before_script: + - cd ../ + - mv ansible-role-${ROLE_NAME} fabiorphp.${ROLE_NAME} + - cd fabiorphp.${ROLE_NAME} + +script: + - molecule test diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..9e3ac6f --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at fabiorphp@gmail.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..a73e497 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,56 @@ +# Contributing + +By participating to this project, you agree to abide our [code of conduct](/CODE_OF_CONDUCT.md). + +## Setup your machine + +Prerequisites: + +* [Python](https://www.python.org) +* [Ansible](https://ansible.com/) +* [Docker](https://docker.com) + +Clone `ansible-role-consul` from source into your favorite path: +```sh +$ git clone git@github.com:fabiorphp/ansible-role-consul.git +$ cd ansible-role-consul +``` + +Install Python dependencies (Please use the Python Virtualenv): +```sh +$ pip install -r requirements.txt +``` + +## Running tests +After the installation of python dependencies run the command below: +```sh +$ molecule test +``` + +## Create a commit + +Commit messages should be well formatted. +Start your commit message with the type. Choose one of the following: +`feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`, `revert`, `add`, `remove`, `move`, `bump`, `update`, `release` + +After a colon, you should give the message a title, starting with uppercase and ending without a dot. +Keep the width of the text at 72 chars. +The title must be followed with a newline, then a more detailed description. + +Please reference any GitHub issues on the last line of the commit message (e.g. `See #123`, `Closes #123`, `Fixes #123`). + +An example: + +``` +docs: Add example for --release-notes flag + +I added an example to the docs of the `--release-notes` flag to make +the usage more clear. The example is an realistic use case and might +help others to generate their own changelog. + +See #284 +``` + +## Submit a pull request + +Push your branch to your `ansible-role-consul` fork and open a pull request against the master branch. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4bc5c44 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2019 Fábio da Silva Ribeiro + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..12ac50f --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Ansible Role: Consul +An ansible role to install and configure Consul agent. + +## Requirements +- [Ansible >= 2.5](https://ansible.com/) + +## Dependencies +None. + +## Author Information +This role was created in 2019 by [Fábio Ribeiro](https://github.com/fabiorphp). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..d6e305f --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for fabiorphp.consul diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..ea50a01 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,20 @@ +--- +dependencies: [] + +galaxy_info: + author: fabiorphp + description: An ansible role to install and configure Consul agent. + license: "license (BSD, MIT)" + min_ansible_version: 2.5 + platforms: + - name: EL + versions: + - 7 + galaxy_tags: + - hashicorp + - consul + - service + - discovery + - mesh + - kv + - health diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..0a60553 --- /dev/null +++ b/molecule/default/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 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 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 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/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..8f57536 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,22 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint + options: + config-file: molecule/default/yaml-lint.yml +platforms: + - name: instance + image: centos:7 +provisioner: + name: ansible + lint: + name: ansible-lint +scenario: + name: default +verifier: + name: testinfra + lint: + name: flake8 diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml new file mode 100644 index 0000000..dfdf128 --- /dev/null +++ b/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: fabiorphp.consul diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py new file mode 100644 index 0000000..eedd64a --- /dev/null +++ b/molecule/default/tests/test_default.py @@ -0,0 +1,14 @@ +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/yaml-lint.yml b/molecule/default/yaml-lint.yml new file mode 100644 index 0000000..f14ed57 --- /dev/null +++ b/molecule/default/yaml-lint.yml @@ -0,0 +1,6 @@ +--- +extends: default +rules: + line-length: + max: 180 + level: warning diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4cfd464 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +ansible>=2.5 +docker-py==1.10.6 +molecule==2.19.0 +pyOpenSSL==18.0.0 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..4b2296d --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for fabiorphp.consul