Browse Source

[FIX] the role

master
Justin Lecher 2 months ago
parent
commit
ddfcf8074b
  1. 2
      .gitignore
  2. 2
      roles/consul/README.md
  3. 3
      roles/consul/molecule/default/converge.yml
  4. 10
      roles/consul/molecule/default/molecule.yml
  5. 9
      roles/consul/molecule/default/prepare.yml
  6. 12
      roles/consul/molecule/default/tests/test_role.py
  7. 11
      roles/consul/tasks/main.yml
  8. 1
      roles/consul/tasks/manual.yml
  9. 2
      roles/consul/tasks/x86_64.yml

2
.gitignore

@ -27,3 +27,5 @@ packer_cache/
# CUSTOM
setup*done
tmp
pytestdebug.log

2
roles/consul/README.md

@ -14,7 +14,7 @@ Role Variables
| Variable | Type | Default | Description |
| --- | --- | --- | --- |
| consul_encryption_key | string | null | use `consul keygen` to generate key |
| consul_retry_join | list | null | Known neighbours to bootstrap the cluster |
| consul_retry_join | list | null | Known neighbors to bootstrap the cluster |
Dependencies
------------

3
roles/consul/molecule/default/converge.yml

@ -7,3 +7,6 @@
- name: "Include consul role"
include_role:
name: "consul"
vars:
consul_encryption_key: "PQVtXboZr8F9n0I/H54eVKOJ6s8e1MIaW+MHcrmuKSo="
consul_retry_join: []

10
roles/consul/molecule/default/molecule.yml

@ -63,10 +63,12 @@ provisioner:
diff:
always: yes
verifier:
name: ansible
# name: testinfra
# options:
# v: 1
name: testinfra
options:
x: yes
v: 2
l: yes
color: "yes"
lint: |
set -e
yamllint .

9
roles/consul/molecule/default/prepare.yml

@ -0,0 +1,9 @@
---
- name: Prepare
hosts: all
tasks:
- name: Refresh cache
apt:
update_cache: yes
cache_valid_time: 3600
when: ansible_pkg_mgr == 'apt'

12
roles/consul/molecule/default/tests/test_role.py

@ -1 +1,13 @@
# Add your testinfra code here
import pytest
def test_consul_service(host):
assert host.service("consul").is_running
@pytest.mark.parametrize("port", [8300, 8301, 8302, 8500, 8600])
def test_consul_listen(host, port):
facts = host.ansible.get_variables()
assert host.socket(f"tcp://{facts['ansible_default_ipv4']['address']['__ansible_unsafe']}:{port}").is_listening

11
roles/consul/tasks/main.yml

@ -31,3 +31,14 @@
state: started
enabled: yes
when: not ansible_check_mode
- name: Wait for running service
wait_for:
port: "{{ item }}"
host: "{{ ansible_default_ipv4.address }}"
loop:
- 8300
- 8301
- 8302
- 8500
- 8600

1
roles/consul/tasks/manual.yml

@ -30,6 +30,7 @@
template:
src: consul.service.j2
dest: /etc/systemd/system/consul.service
mode: '0644'
notify:
- Systemd Daemon Reload
- Restart consul

2
roles/consul/tasks/x86_64.yml

@ -4,5 +4,5 @@
name: hashicorp_repo
- name: Install consul
apt:
package:
name: consul
Loading…
Cancel
Save