Skip to content

Commit

Permalink
Merge branch 'master' of github.com:robertdebock/ansible-role-dovecot
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdebock committed Nov 26, 2018
2 parents c648c8a + 75c4c50 commit f1889c9
Show file tree
Hide file tree
Showing 26 changed files with 415 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ dovecot_mailbox_location: mbox:~/mail:INBOX=/var/spool/mail/%u
# To update all packages installed by this roles, set `dovecot_package_state` to `latest`.
dovecot_package_state: present
# Some Docker containers do not allow managing services, rebooting and writing
# to some locations in /etc. The role skips tasks that will typically fail in
# Docker. With this parameter you can tell the role to -not- skip these tasks.
dovecot_ignore_docker: yes
```

Requirements
Expand Down
5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ dovecot_mailbox_location: mbox:~/mail:INBOX=/var/spool/mail/%u

# To update all packages installed by this roles, set `dovecot_package_state` to `latest`.
dovecot_package_state: present

# Some Docker containers do not allow managing services, rebooting and writing
# to some locations in /etc. The role skips tasks that will typically fail in
# Docker. With this parameter you can tell the role to -not- skip these tasks.
dovecot_ignore_docker: yes
4 changes: 4 additions & 0 deletions molecule/alpine-edge/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ platforms:
command: sh -c "while true ; do sleep 1 ; done"
provisioner:
name: ansible
inventory:
group_vars:
all:
dovecot_ignore_docker: no
lint:
name: ansible-lint
scenario:
Expand Down
4 changes: 4 additions & 0 deletions molecule/alpine-latest/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ platforms:
command: sh -c "while true ; do sleep 1 ; done"
provisioner:
name: ansible
inventory:
group_vars:
all:
dovecot_ignore_docker: no
lint:
name: ansible-lint
scenario:
Expand Down
4 changes: 4 additions & 0 deletions molecule/archlinux/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ platforms:
image: base/archlinux
provisioner:
name: ansible
inventory:
group_vars:
all:
dovecot_ignore_docker: no
lint:
name: ansible-lint
scenario:
Expand Down
4 changes: 4 additions & 0 deletions molecule/centos-6/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ platforms:
image: centos:6
provisioner:
name: ansible
inventory:
group_vars:
all:
dovecot_ignore_docker: no
lint:
name: ansible-lint
scenario:
Expand Down
4 changes: 4 additions & 0 deletions molecule/centos-latest/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ platforms:
image: centos:latest
provisioner:
name: ansible
inventory:
group_vars:
all:
dovecot_ignore_docker: no
lint:
name: ansible-lint
scenario:
Expand Down
4 changes: 4 additions & 0 deletions molecule/debian-latest/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ platforms:
image: debian:latest
provisioner:
name: ansible
inventory:
group_vars:
all:
dovecot_ignore_docker: no
lint:
name: ansible-lint
scenario:
Expand Down
4 changes: 4 additions & 0 deletions molecule/debian-stable/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ platforms:
image: debian:stable
provisioner:
name: ansible
inventory:
group_vars:
all:
dovecot_ignore_docker: no
lint:
name: ansible-lint
scenario:
Expand Down
4 changes: 4 additions & 0 deletions molecule/debian-unstable/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ platforms:
image: debian:unstable
provisioner:
name: ansible
inventory:
group_vars:
all:
dovecot_ignore_docker: no
lint:
name: ansible-lint
scenario:
Expand Down
6 changes: 6 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ platforms:
image: ubuntu:artful
- name: dovecot-ubuntu-devel
image: ubuntu:devel
- name: dovecot-ubuntu-latest
image: ubuntu:latest
provisioner:
name: ansible
inventory:
group_vars:
all:
dovecot_ignore_docker: no
lint:
name: ansible-lint
config_options:
Expand Down
15 changes: 15 additions & 0 deletions molecule/ec2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Amazon EC2

To test on Amazon elastic compute cloud (EC2), set this variable:

```
export EC2_REGION=eu-central-1
```

And save the credentials:
```
cat ~/.aws/credentials
[default]
aws_access_key_id=YOUR_KEY_ID
aws_secret_access_key=YOUR_ACCESS_KEY
```
125 changes: 125 additions & 0 deletions molecule/ec2/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
vars:
ssh_user: ec2-user
ssh_port: 22

security_group_name: molecule
security_group_description: Security group for testing Molecule
security_group_rules:
- proto: tcp
from_port: "{{ ssh_port }}"
to_port: "{{ ssh_port }}"
cidr_ip: '0.0.0.0/0'
- proto: icmp
from_port: 8
to_port: -1
cidr_ip: '0.0.0.0/0'
security_group_rules_egress:
- proto: -1
from_port: 0
to_port: 0
cidr_ip: '0.0.0.0/0'

keypair_name: molecule_key
keypair_path: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ssh_key"
tasks:
- name: Create security group
ec2_group:
name: "{{ security_group_name }}"
description: "{{ security_group_name }}"
rules: "{{ security_group_rules }}"
rules_egress: "{{ security_group_rules_egress }}"

- name: Test for presence of local keypair
stat:
path: "{{ keypair_path }}"
register: keypair_local

- name: Delete remote keypair
ec2_key:
name: "{{ keypair_name }}"
state: absent
when: not keypair_local.stat.exists

- name: Create keypair
ec2_key:
name: "{{ keypair_name }}"
register: keypair

- name: Persist the keypair
copy:
dest: "{{ keypair_path }}"
content: "{{ keypair.key.private_key }}"
mode: 0600
when: keypair.changed

- name: Create molecule instance(s)
ec2:
key_name: "{{ keypair_name }}"
image: "{{ item.image }}"
instance_type: "{{ item.instance_type }}"
vpc_subnet_id: "{{ item.vpc_subnet_id }}"
group: "{{ security_group_name }}"
instance_tags:
instance: "{{ item.name }}"
wait: true
assign_public_ip: true
exact_count: 1
count_tag:
instance: "{{ item.name }}"
register: server
with_items: "{{ molecule_yml.platforms }}"
async: 7200
poll: 0

- name: Wait for instance(s) creation to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: ec2_jobs
until: ec2_jobs.finished
retries: 300
with_items: "{{ server.results }}"

# Mandatory configuration for Molecule to function.

- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ item.instances[0].tags.instance }}",
'address': "{{ item.instances[0].public_ip }}",
'user': "{{ ssh_user }}",
'port': "{{ ssh_port }}",
'identity_file': "{{ keypair_path }}",
'instance_ids': "{{ item.instance_ids }}", }
with_items: "{{ ec2_jobs.results }}"
register: instance_config_dict
when: server.changed | bool

- name: Convert instance config dict to a list
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
when: server.changed | bool

- name: Dump instance config
copy:
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool

- name: Wait for SSH
wait_for:
port: "{{ ssh_port }}"
host: "{{ item.address }}"
search_regex: SSH
delay: 10
timeout: 320
with_items: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"

- name: Wait for boot process to finish
pause:
minutes: 2
47 changes: 47 additions & 0 deletions molecule/ec2/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
tasks:
- block:
- name: Populate instance config
set_fact:
instance_conf: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"
skip_instances: false
rescue:
- name: Populate instance config when file missing
set_fact:
instance_conf: {}
skip_instances: true

- name: Destroy molecule instance(s)
ec2:
state: absent
instance_ids: "{{ item.instance_ids }}"
register: server
with_items: "{{ instance_conf }}"
when: not skip_instances
async: 7200
poll: 0

- name: Wait for instance(s) deletion to complete
async_status:
jid: "{{ item.ansible_job_id }}"
register: ec2_jobs
until: ec2_jobs.finished
retries: 300
with_items: "{{ server.results }}"

# Mandatory configuration for Molecule to function.

- name: Populate instance config
set_fact:
instance_conf: {}

- name: Dump instance config
copy:
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool
81 changes: 81 additions & 0 deletions molecule/ec2/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
dependency:
name: galaxy
options:
role-file: requirements.yml
driver:
name: ec2
lint:
name: yamllint
platforms:
# - name: rhel-7
# image: ami-c86c3f23
# instance_type: t2.micro
# vpc_subnet_id: subnet-0e688067
# - name: sles-15
# image: ami-0a1886cf45f944eb1
# instance_type: t2.micro
# vpc_subnet_id: subnet-0e688067
- name: dovecot-ubuntu-18.04
image: ami-0bdf93799014acdc4
instance_type: t2.micro
vpc_subnet_id: subnet-0e688067
- name: dovecot-amazon-linux-2
image: ami-02ea8f348fa28c108
instance_type: t2.micro
vpc_subnet_id: subnet-0e688067
- name: dovecot-centos-7
image: ami-9a183671
instance_type: t2.micro
vpc_subnet_id: subnet-0e688067
- name: dovecot-fedora-29
image: ami-0f904cfaa69a1c64c
instance_type: t2.micro
vpc_subnet_id: subnet-0e688067
provisioner:
name: ansible
lint:
name: ansible-lint
config_options:
defaults:
callback_plugins: /usr/lib/python2.7/site-packages/ara/plugins/callbacks
inventory:
host_vars:
dovecot-ubuntu-18.04:
ansible_user: ubuntu
dovecot-centos-7:
ansible_user: centos
dovecot-fedora-29:
ansible_user: fedora
scenario:
name: ec2
create_sequence:
- create
check_sequence:
- destroy
- dependency
- create
- converge
- check
- destroy
converge_sequence:
- dependency
- create
- converge
destroy_sequence:
- destroy
test_sequence:
- lint
- destroy
- dependency
- syntax
- create
- converge
- idempotence
- side_effect
- verify
- destroy
verifier:
name: goss
lint:
name: yamllint
Loading

0 comments on commit f1889c9

Please sign in to comment.