This commit is contained in:
parent
a1252c600a
commit
2752f6842e
105
.drone.jsonnet
105
.drone.jsonnet
@ -1,20 +1,3 @@
|
|||||||
local AnsibleVersions(version="latest", package="ansible") = {
|
|
||||||
name: "ansible-" + version,
|
|
||||||
image: "python:3.7",
|
|
||||||
pull: "always",
|
|
||||||
environment: {
|
|
||||||
PY_COLORS: 1
|
|
||||||
},
|
|
||||||
commands: [
|
|
||||||
"pip install " + package + " ansible-later~=0.2.0 -qq",
|
|
||||||
"git clone https://gitea.rknet.org/ansible/ansible-later-policy.git ~/policy",
|
|
||||||
"ansible-later -c ~/policy/config.yml"
|
|
||||||
],
|
|
||||||
depends_on: [
|
|
||||||
"clone",
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
local PipelineLinting = {
|
local PipelineLinting = {
|
||||||
kind: "pipeline",
|
kind: "pipeline",
|
||||||
name: "linting",
|
name: "linting",
|
||||||
@ -23,8 +6,17 @@ local PipelineLinting = {
|
|||||||
arch: "amd64",
|
arch: "amd64",
|
||||||
},
|
},
|
||||||
steps: [
|
steps: [
|
||||||
AnsibleVersions(version="latest", package="ansible"),
|
{
|
||||||
AnsibleVersions(version="master", package="git+https://github.com/ansible/ansible.git@devel"),
|
name: "ansible-later",
|
||||||
|
image: "xoxys/ansible-later:latest",
|
||||||
|
environment: {
|
||||||
|
PY_COLORS: 1
|
||||||
|
},
|
||||||
|
commands: [
|
||||||
|
"git clone https://gitea.rknet.org/ansible/ansible-later-policy.git ~/policy",
|
||||||
|
"ansible-later -c ~/policy/config.yml"
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
trigger: {
|
trigger: {
|
||||||
ref: ["refs/heads/master", "refs/tags/**", "refs/pull/**"],
|
ref: ["refs/heads/master", "refs/tags/**", "refs/pull/**"],
|
||||||
@ -38,27 +30,27 @@ local PipelineDeployment = {
|
|||||||
os: "linux",
|
os: "linux",
|
||||||
arch: "amd64",
|
arch: "amd64",
|
||||||
},
|
},
|
||||||
|
concurrency: {
|
||||||
|
limit: 1
|
||||||
|
},
|
||||||
workspace: {
|
workspace: {
|
||||||
base: "/drone/src",
|
base: "/drone/src",
|
||||||
path: "xoxys.iptables"
|
path: "xoxys.iptables"
|
||||||
},
|
},
|
||||||
steps: [
|
steps: [
|
||||||
{
|
{
|
||||||
name: "molecule",
|
name: "ansible-molecule",
|
||||||
image: "xoxys/molecule:ec2-linux-amd64",
|
image: "xoxys/molecule:do-linux-amd64",
|
||||||
pull: "always",
|
|
||||||
environment: {
|
environment: {
|
||||||
ANSIBLE_ROLES_PATH: "/drone/src",
|
DO_API_KEY: { "from_secret": "do_api_key" },
|
||||||
AWS_ACCESS_KEY_ID: { "from_secret": "aws_access_key_id" },
|
USER: "root",
|
||||||
AWS_SECRET_ACCESS_KEY: { "from_secret": "aws_secret_access_key" },
|
|
||||||
AWS_REGION: "eu-central-1",
|
|
||||||
MOLECULE_CUSTOM_MODULES_REPO: "https://gitea.rknet.org/ansible/custom_modules",
|
MOLECULE_CUSTOM_MODULES_REPO: "https://gitea.rknet.org/ansible/custom_modules",
|
||||||
MOLECULE_CUSTOM_FILTERS_REPO: "https://gitea.rknet.org/ansible/custom_filters",
|
MOLECULE_CUSTOM_FILTERS_REPO: "https://gitea.rknet.org/ansible/custom_filters",
|
||||||
PY_COLORS: 1
|
PY_COLORS: 1
|
||||||
},
|
},
|
||||||
commands: [
|
commands: [
|
||||||
"/bin/bash /docker-entrypoint.sh",
|
"/bin/bash /docker-entrypoint.sh",
|
||||||
"molecule test --scenario-name ec2-centos-7",
|
"molecule test -s default",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -70,9 +62,55 @@ local PipelineDeployment = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
local PipelineNotifications = {
|
local PipelineDocumentation = {
|
||||||
kind: "pipeline",
|
kind: "pipeline",
|
||||||
name: "notifications",
|
name: "documentation",
|
||||||
|
platform: {
|
||||||
|
os: "linux",
|
||||||
|
arch: "amd64",
|
||||||
|
},
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
name: "ansible-doctor",
|
||||||
|
image: "xoxys/ansible-doctor:latest",
|
||||||
|
environment: {
|
||||||
|
ANSIBLE_DOCTOR_LOG_LEVEL: "INFO",
|
||||||
|
ANSIBLE_DOCTOR_FORCE_OVERWRITE: true,
|
||||||
|
ANSIBLE_DOCTOR_EXCLUDE_FILES: "molecule/",
|
||||||
|
ANSIBLE_DOCTOR_CUSTOM_HEADER: "HEADER.md",
|
||||||
|
PY_COLORS: 1
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "push-to-repo",
|
||||||
|
image: "plugins/git-action:latest",
|
||||||
|
settings: {
|
||||||
|
actions: ["commit", "push"],
|
||||||
|
author_email: "shipper@rknet.org",
|
||||||
|
author_name: "DroneShipper",
|
||||||
|
branch: "master",
|
||||||
|
message: "[SKIP CI] update readme",
|
||||||
|
remote: "https://gitea.rknet.org/ansible/xoxys.iptables",
|
||||||
|
netrc_machine: "gitea.rknet.org",
|
||||||
|
netrc_username: {"from_secret": "gitea_username"},
|
||||||
|
netrc_password: {"from_secret": "gitea_token"},
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
ref: ["refs/heads/master"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
depends_on: [
|
||||||
|
"deployment",
|
||||||
|
],
|
||||||
|
trigger: {
|
||||||
|
ref: ["refs/heads/master", "refs/tags/**", "refs/pull/**"],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
local PipelineNotification= {
|
||||||
|
kind: "pipeline",
|
||||||
|
name: "notification",
|
||||||
platform: {
|
platform: {
|
||||||
os: "linux",
|
os: "linux",
|
||||||
arch: "amd64",
|
arch: "amd64",
|
||||||
@ -85,8 +123,8 @@ local PipelineNotifications = {
|
|||||||
name: "matrix",
|
name: "matrix",
|
||||||
image: "plugins/matrix",
|
image: "plugins/matrix",
|
||||||
settings: {
|
settings: {
|
||||||
homeserver: "https://matrix.rknet.org",
|
homeserver: { "from_secret": "matrix_homeserver" },
|
||||||
roomid: "MtidqQXWWAtQcByBhH:rknet.org",
|
roomid: { "from_secret": "matrix_roomid" },
|
||||||
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}",
|
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}",
|
||||||
username: { "from_secret": "matrix_username" },
|
username: { "from_secret": "matrix_username" },
|
||||||
password: { "from_secret": "matrix_password" },
|
password: { "from_secret": "matrix_password" },
|
||||||
@ -94,7 +132,7 @@ local PipelineNotifications = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
depends_on: [
|
depends_on: [
|
||||||
"deployment",
|
"documentation",
|
||||||
],
|
],
|
||||||
trigger: {
|
trigger: {
|
||||||
status: [ "success", "failure" ],
|
status: [ "success", "failure" ],
|
||||||
@ -105,5 +143,6 @@ local PipelineNotifications = {
|
|||||||
[
|
[
|
||||||
PipelineLinting,
|
PipelineLinting,
|
||||||
PipelineDeployment,
|
PipelineDeployment,
|
||||||
PipelineNotifications,
|
PipelineDocumentation,
|
||||||
|
PipelineNotification,
|
||||||
]
|
]
|
||||||
|
98
.drone.yml
98
.drone.yml
@ -7,29 +7,13 @@ platform:
|
|||||||
arch: amd64
|
arch: amd64
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: ansible-latest
|
- name: ansible-later
|
||||||
pull: always
|
image: xoxys/ansible-later:latest
|
||||||
image: python:3.7
|
|
||||||
commands:
|
commands:
|
||||||
- pip install ansible ansible-later~=0.2.0 -qq
|
|
||||||
- git clone https://gitea.rknet.org/ansible/ansible-later-policy.git ~/policy
|
- git clone https://gitea.rknet.org/ansible/ansible-later-policy.git ~/policy
|
||||||
- ansible-later -c ~/policy/config.yml
|
- ansible-later -c ~/policy/config.yml
|
||||||
environment:
|
environment:
|
||||||
PY_COLORS: 1
|
PY_COLORS: 1
|
||||||
depends_on:
|
|
||||||
- clone
|
|
||||||
|
|
||||||
- name: ansible-master
|
|
||||||
pull: always
|
|
||||||
image: python:3.7
|
|
||||||
commands:
|
|
||||||
- "pip install git+https://github.com/ansible/ansible.git@devel ansible-later~=0.2.0 -qq"
|
|
||||||
- git clone https://gitea.rknet.org/ansible/ansible-later-policy.git ~/policy
|
|
||||||
- ansible-later -c ~/policy/config.yml
|
|
||||||
environment:
|
|
||||||
PY_COLORS: 1
|
|
||||||
depends_on:
|
|
||||||
- clone
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
ref:
|
ref:
|
||||||
@ -45,27 +29,26 @@ platform:
|
|||||||
os: linux
|
os: linux
|
||||||
arch: amd64
|
arch: amd64
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
limit: 1
|
||||||
|
|
||||||
workspace:
|
workspace:
|
||||||
base: /drone/src
|
base: /drone/src
|
||||||
path: xoxys.iptables
|
path: xoxys.iptables
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: molecule
|
- name: ansible-molecule
|
||||||
pull: always
|
image: xoxys/molecule:do-linux-amd64
|
||||||
image: xoxys/molecule:ec2-linux-amd64
|
|
||||||
commands:
|
commands:
|
||||||
- /bin/bash /docker-entrypoint.sh
|
- /bin/bash /docker-entrypoint.sh
|
||||||
- molecule test --scenario-name ec2-centos-7
|
- molecule test -s default
|
||||||
environment:
|
environment:
|
||||||
ANSIBLE_ROLES_PATH: /drone/src
|
DO_API_KEY:
|
||||||
AWS_ACCESS_KEY_ID:
|
from_secret: do_api_key
|
||||||
from_secret: aws_access_key_id
|
|
||||||
AWS_REGION: eu-central-1
|
|
||||||
AWS_SECRET_ACCESS_KEY:
|
|
||||||
from_secret: aws_secret_access_key
|
|
||||||
MOLECULE_CUSTOM_FILTERS_REPO: https://gitea.rknet.org/ansible/custom_filters
|
MOLECULE_CUSTOM_FILTERS_REPO: https://gitea.rknet.org/ansible/custom_filters
|
||||||
MOLECULE_CUSTOM_MODULES_REPO: https://gitea.rknet.org/ansible/custom_modules
|
MOLECULE_CUSTOM_MODULES_REPO: https://gitea.rknet.org/ansible/custom_modules
|
||||||
PY_COLORS: 1
|
PY_COLORS: 1
|
||||||
|
USER: root
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
ref:
|
ref:
|
||||||
@ -77,7 +60,54 @@ depends_on:
|
|||||||
|
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: notifications
|
name: documentation
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: ansible-doctor
|
||||||
|
image: xoxys/ansible-doctor:latest
|
||||||
|
environment:
|
||||||
|
ANSIBLE_DOCTOR_CUSTOM_HEADER: HEADER.md
|
||||||
|
ANSIBLE_DOCTOR_EXCLUDE_FILES: molecule/
|
||||||
|
ANSIBLE_DOCTOR_FORCE_OVERWRITE: true
|
||||||
|
ANSIBLE_DOCTOR_LOG_LEVEL: INFO
|
||||||
|
PY_COLORS: 1
|
||||||
|
|
||||||
|
- name: push-to-repo
|
||||||
|
image: plugins/git-action:latest
|
||||||
|
settings:
|
||||||
|
actions:
|
||||||
|
- commit
|
||||||
|
- push
|
||||||
|
author_email: "shipper@rknet.org"
|
||||||
|
author_name: DroneShipper
|
||||||
|
branch: master
|
||||||
|
message: "[SKIP CI] update readme"
|
||||||
|
netrc_machine: gitea.rknet.org
|
||||||
|
netrc_password:
|
||||||
|
from_secret: gitea_token
|
||||||
|
netrc_username:
|
||||||
|
from_secret: gitea_username
|
||||||
|
remote: https://gitea.rknet.org/ansible/xoxys.iptables
|
||||||
|
when:
|
||||||
|
ref:
|
||||||
|
- refs/heads/master
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/master
|
||||||
|
- "refs/tags/**"
|
||||||
|
- "refs/pull/**"
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- deployment
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: notification
|
||||||
|
|
||||||
platform:
|
platform:
|
||||||
os: linux
|
os: linux
|
||||||
@ -90,10 +120,12 @@ steps:
|
|||||||
- name: matrix
|
- name: matrix
|
||||||
image: plugins/matrix
|
image: plugins/matrix
|
||||||
settings:
|
settings:
|
||||||
homeserver: https://matrix.rknet.org
|
homeserver:
|
||||||
|
from_secret: matrix_homeserver
|
||||||
password:
|
password:
|
||||||
from_secret: matrix_password
|
from_secret: matrix_password
|
||||||
roomid: MtidqQXWWAtQcByBhH:rknet.org
|
roomid:
|
||||||
|
from_secret: matrix_roomid
|
||||||
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}"
|
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}"
|
||||||
username:
|
username:
|
||||||
from_secret: matrix_username
|
from_secret: matrix_username
|
||||||
@ -107,10 +139,10 @@ trigger:
|
|||||||
- failure
|
- failure
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- deployment
|
- documentation
|
||||||
|
|
||||||
---
|
---
|
||||||
kind: signature
|
kind: signature
|
||||||
hmac: e757be9a5a8f68bb72cd6b38fad5d601a344e7ec4e08b92d64de87349e51a9a9
|
hmac: 5d5bee0071a971a17457c2f7bcd2c1983a5e31d0f8d5fe133b9c2d2d77da4928
|
||||||
|
|
||||||
...
|
...
|
||||||
|
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# ---> Ansible
|
||||||
|
*.retry
|
||||||
|
filter/plugins/
|
||||||
|
library
|
||||||
|
|
||||||
|
# ---> Python
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
4
HEADER.md
Normal file
4
HEADER.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# xoxys.iptables
|
||||||
|
|
||||||
|
[![Build Status](https://drone.rknet.org/api/badges/ansible/xoxys.iptables/status.svg)](https://drone.rknet.org/ansible/xoxys.iptables)
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
# Default head (allow) rules
|
# @var iptables_default_head:description: Default head (allow) rules.
|
||||||
iptables_default_head: |
|
iptables_default_head: |
|
||||||
-P INPUT ACCEPT
|
-P INPUT ACCEPT
|
||||||
-P FORWARD ACCEPT
|
-P FORWARD ACCEPT
|
||||||
@ -9,13 +9,15 @@ iptables_default_head: |
|
|||||||
-A INPUT -p icmp --icmp-type echo-request -j ACCEPT
|
-A INPUT -p icmp --icmp-type echo-request -j ACCEPT
|
||||||
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
|
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
|
||||||
|
|
||||||
# Default tail (deny) rules
|
# @var iptables_default_tail:description: Default tail (deny) rules.
|
||||||
iptables_default_tail: |
|
iptables_default_tail: |
|
||||||
-A INPUT -j REJECT
|
-A INPUT -j REJECT
|
||||||
-A FORWARD -j REJECT
|
-A FORWARD -j REJECT
|
||||||
|
|
||||||
iptables_custom_rules: []
|
iptables_custom_rules: []
|
||||||
|
|
||||||
|
# @var iptables_keep_unmanaged:description: >
|
||||||
# By default this role deletes all iptables rules which are not managed by Ansible.
|
# By default this role deletes all iptables rules which are not managed by Ansible.
|
||||||
# Set this to 'yes', if you want the role to keep unmanaged rules.
|
# Set this to 'yes', if you want the role to keep unmanaged rules.
|
||||||
|
# @end
|
||||||
iptables_keep_unmanaged: no
|
iptables_keep_unmanaged: no
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
*******
|
|
||||||
Amazon Web Services driver installation guide
|
|
||||||
*******
|
|
||||||
|
|
||||||
Requirements
|
|
||||||
============
|
|
||||||
|
|
||||||
* An AWS credentials rc file
|
|
||||||
|
|
||||||
Install
|
|
||||||
=======
|
|
||||||
|
|
||||||
Please refer to the `Virtual environment`_ documentation for installation best
|
|
||||||
practices. If not using a virtual environment, please consider passing the
|
|
||||||
widely recommended `'--user' flag`_ when invoking ``pip``.
|
|
||||||
|
|
||||||
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
|
|
||||||
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
$ pip install 'molecule[ec2]'
|
|
@ -3,100 +3,66 @@
|
|||||||
hosts: localhost
|
hosts: localhost
|
||||||
connection: local
|
connection: local
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
|
no_log: "{{ molecule_no_log }}"
|
||||||
vars:
|
vars:
|
||||||
ssh_user: ubuntu
|
ssh_user: root
|
||||||
ssh_port: 22
|
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_name: molecule_key
|
||||||
keypair_path: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ssh_key"
|
keypair_path: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ssh_key"
|
||||||
tasks:
|
tasks:
|
||||||
- name: Create security group
|
- name: Create local keypair
|
||||||
ec2_group:
|
user:
|
||||||
name: "{{ security_group_name }}"
|
name: "{{ lookup('env', 'USER') }}"
|
||||||
description: "{{ security_group_name }}"
|
generate_ssh_key: true
|
||||||
rules: "{{ security_group_rules }}"
|
ssh_key_file: "{{ keypair_path }}"
|
||||||
rules_egress: "{{ security_group_rules_egress }}"
|
register: local_keypair
|
||||||
|
|
||||||
- name: Test for presence of local keypair
|
- name: Create remote keypair
|
||||||
stat:
|
digital_ocean_sshkey:
|
||||||
path: "{{ keypair_path }}"
|
|
||||||
register: keypair_local
|
|
||||||
|
|
||||||
- name: Delete remote keypair
|
|
||||||
ec2_key:
|
|
||||||
name: "{{ keypair_name }}"
|
name: "{{ keypair_name }}"
|
||||||
state: absent
|
ssh_pub_key: "{{ local_keypair.ssh_public_key }}"
|
||||||
when: not keypair_local.stat.exists
|
state: present
|
||||||
|
register: remote_keypair
|
||||||
- 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)
|
- name: Create molecule instance(s)
|
||||||
ec2:
|
digital_ocean_droplet:
|
||||||
key_name: "{{ keypair_name }}"
|
name: "{{ item.name }}"
|
||||||
image: "{{ item.image }}"
|
unique_name: true
|
||||||
instance_type: "{{ item.instance_type }}"
|
region: "{{ item.region_id }}"
|
||||||
vpc_subnet_id: "{{ item.vpc_subnet_id }}"
|
image: "{{ item.image_id }}"
|
||||||
group: "{{ security_group_name }}"
|
size: "{{ item.size_id }}"
|
||||||
instance_tags:
|
ssh_keys: "{{ remote_keypair.data.ssh_key.id }}"
|
||||||
instance: "{{ item.name }}"
|
|
||||||
wait: true
|
wait: true
|
||||||
assign_public_ip: true
|
wait_timeout: 300
|
||||||
exact_count: 1
|
state: present
|
||||||
count_tag:
|
|
||||||
instance: "{{ item.name }}"
|
|
||||||
register: server
|
register: server
|
||||||
with_items: "{{ molecule_yml.platforms }}"
|
loop: "{{ molecule_yml.platforms }}"
|
||||||
async: 7200
|
async: 7200
|
||||||
poll: 0
|
poll: 0
|
||||||
|
|
||||||
- name: Wait for instance(s) creation to complete
|
- name: Wait for instance(s) creation to complete
|
||||||
async_status:
|
async_status:
|
||||||
jid: "{{ item.ansible_job_id }}"
|
jid: "{{ item.ansible_job_id }}"
|
||||||
register: ec2_jobs
|
register: digitalocean_jobs
|
||||||
until: ec2_jobs.finished
|
until: digitalocean_jobs.finished
|
||||||
retries: 300
|
retries: 300
|
||||||
with_items: "{{ server.results }}"
|
loop: "{{ server.results }}"
|
||||||
|
|
||||||
# Mandatory configuration for Molecule to function.
|
# Mandatory configuration for Molecule to function.
|
||||||
|
|
||||||
- name: Populate instance config dict
|
- name: Populate instance config dict
|
||||||
set_fact:
|
set_fact:
|
||||||
instance_conf_dict: {
|
instance_conf_dict: {
|
||||||
'instance': "{{ item.instances[0].tags.instance }}",
|
'instance': "{{ item.data.droplet.name }}",
|
||||||
'address': "{{ item.instances[0].public_ip }}",
|
'address': "{{ item.data.ip_address }}",
|
||||||
'user': "{{ ssh_user }}",
|
'user': "{{ ssh_user }}",
|
||||||
'port': "{{ ssh_port }}",
|
'port': "{{ ssh_port }}",
|
||||||
'identity_file': "{{ keypair_path }}",
|
'identity_file': "{{ keypair_path }}",
|
||||||
'instance_ids': "{{ item.instance_ids }}", }
|
'droplet_id': "{{ item.data.droplet.id }}",
|
||||||
with_items: "{{ ec2_jobs.results }}"
|
'ssh_key_id': "{{ remote_keypair.data.ssh_key.id }}",
|
||||||
|
}
|
||||||
|
loop: "{{ digitalocean_jobs.results }}"
|
||||||
register: instance_config_dict
|
register: instance_config_dict
|
||||||
when: server.changed | bool
|
when: server.changed | bool
|
||||||
|
|
||||||
@ -118,8 +84,4 @@
|
|||||||
search_regex: SSH
|
search_regex: SSH
|
||||||
delay: 10
|
delay: 10
|
||||||
timeout: 320
|
timeout: 320
|
||||||
with_items: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"
|
loop: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"
|
||||||
|
|
||||||
- name: Wait for boot process to finish
|
|
||||||
pause:
|
|
||||||
minutes: 2
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
hosts: localhost
|
hosts: localhost
|
||||||
connection: local
|
connection: local
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
|
no_log: "{{ molecule_no_log }}"
|
||||||
tasks:
|
tasks:
|
||||||
- block:
|
- block:
|
||||||
- name: Populate instance config
|
- name: Populate instance config
|
||||||
@ -17,11 +17,12 @@
|
|||||||
skip_instances: true
|
skip_instances: true
|
||||||
|
|
||||||
- name: Destroy molecule instance(s)
|
- name: Destroy molecule instance(s)
|
||||||
ec2:
|
digital_ocean_droplet:
|
||||||
|
name: "{{ item.instance }}"
|
||||||
|
id: "{{ item.droplet_id }}"
|
||||||
state: absent
|
state: absent
|
||||||
instance_ids: "{{ item.instance_ids }}"
|
|
||||||
register: server
|
register: server
|
||||||
with_items: "{{ instance_conf }}"
|
loop: "{{ instance_conf | flatten(levels=1) }}"
|
||||||
when: not skip_instances
|
when: not skip_instances
|
||||||
async: 7200
|
async: 7200
|
||||||
poll: 0
|
poll: 0
|
||||||
@ -29,10 +30,16 @@
|
|||||||
- name: Wait for instance(s) deletion to complete
|
- name: Wait for instance(s) deletion to complete
|
||||||
async_status:
|
async_status:
|
||||||
jid: "{{ item.ansible_job_id }}"
|
jid: "{{ item.ansible_job_id }}"
|
||||||
register: ec2_jobs
|
register: digitalocean_jobs
|
||||||
until: ec2_jobs.finished
|
until: digitalocean_jobs.finished
|
||||||
retries: 300
|
retries: 300
|
||||||
with_items: "{{ server.results }}"
|
loop: "{{ server.results }}"
|
||||||
|
|
||||||
|
- name: Delete remote keypair
|
||||||
|
digital_ocean_sshkey:
|
||||||
|
fingerprint: "{{ item.ssh_key_id }}"
|
||||||
|
state: absent
|
||||||
|
loop: "{{ instance_conf | flatten(levels=1) }}"
|
||||||
|
|
||||||
# Mandatory configuration for Molecule to function.
|
# Mandatory configuration for Molecule to function.
|
||||||
|
|
||||||
@ -42,6 +49,6 @@
|
|||||||
|
|
||||||
- name: Dump instance config
|
- name: Dump instance config
|
||||||
copy:
|
copy:
|
||||||
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
|
content: "{{ instance_conf | molecule_to_yaml | molecule_header }}"
|
||||||
dest: "{{ molecule_instance_config }}"
|
dest: "{{ molecule_instance_config }}"
|
||||||
when: server.changed | bool
|
when: server.changed | bool
|
||||||
|
@ -2,18 +2,20 @@
|
|||||||
dependency:
|
dependency:
|
||||||
name: galaxy
|
name: galaxy
|
||||||
driver:
|
driver:
|
||||||
name: ec2
|
name: digitalocean
|
||||||
|
platforms:
|
||||||
|
- name: centos7-iptables
|
||||||
|
region_id: fra1
|
||||||
|
image_id: centos-7-x64
|
||||||
|
size_id: s-1vcpu-1gb
|
||||||
lint:
|
lint:
|
||||||
name: yamllint
|
name: yamllint
|
||||||
platforms:
|
enabled: False
|
||||||
- name: instance
|
|
||||||
image: ami-a5b196c0
|
|
||||||
instance_type: t2.micro
|
|
||||||
vpc_subnet_id: subnet-6456fd1f
|
|
||||||
provisioner:
|
provisioner:
|
||||||
name: ansible
|
name: ansible
|
||||||
lint:
|
lint:
|
||||||
name: ansible-lint
|
name: ansible-lint
|
||||||
|
enabled: False
|
||||||
verifier:
|
verifier:
|
||||||
name: testinfra
|
name: testinfra
|
||||||
lint:
|
lint:
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
---
|
---
|
||||||
- name: Converge
|
- name: Converge
|
||||||
hosts: all
|
hosts: all
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: Add symlink for iptables
|
||||||
|
file:
|
||||||
|
src: /usr/sbin/iptables
|
||||||
|
dest: /usr/bin/iptables
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
state: link
|
||||||
|
become: True
|
||||||
|
become_user: root
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
- role: xoxys.iptables
|
- role: xoxys.iptables
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- name: Install python for Ansible
|
- name: Install python for Ansible
|
||||||
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-zipstream)
|
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
|
||||||
become: true
|
become: true
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
@ -2,13 +2,33 @@ import os
|
|||||||
|
|
||||||
import testinfra.utils.ansible_runner
|
import testinfra.utils.ansible_runner
|
||||||
|
|
||||||
|
import warnings
|
||||||
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
|
|
||||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||||
|
|
||||||
|
|
||||||
def test_hosts_file(host):
|
def test_iptables_is_installed(host):
|
||||||
f = host.file('/etc/hosts')
|
iptables = host.package("iptables")
|
||||||
|
assert iptables.is_installed
|
||||||
|
|
||||||
assert f.exists
|
|
||||||
assert f.user == 'root'
|
def test_iptables_running_and_enabled(host):
|
||||||
assert f.group == 'root'
|
iptables = host.service("iptables")
|
||||||
|
assert iptables.is_running
|
||||||
|
assert iptables.is_enabled
|
||||||
|
|
||||||
|
|
||||||
|
def test_iptables_default_rules(host):
|
||||||
|
defaults = [
|
||||||
|
'-P INPUT ACCEPT',
|
||||||
|
'-A INPUT -m state --state RELATED,ESTABLISHED -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
|
||||||
|
'-A INPUT -i lo -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
|
||||||
|
'-A INPUT -p icmp -m icmp --icmp-type 8 -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
|
||||||
|
'-A INPUT -p tcp -m tcp --dport 22 -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
|
||||||
|
'-A INPUT -m comment --comment "ansible[iptables_default_tail]" -j REJECT --reject-with icmp-port-unreachable'
|
||||||
|
]
|
||||||
|
|
||||||
|
rules = host.iptables.rules("filter", "INPUT")
|
||||||
|
assert defaults == rules
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
*******
|
|
||||||
Amazon Web Services driver installation guide
|
|
||||||
*******
|
|
||||||
|
|
||||||
Requirements
|
|
||||||
============
|
|
||||||
|
|
||||||
* An AWS credentials rc file
|
|
||||||
|
|
||||||
Install
|
|
||||||
=======
|
|
||||||
|
|
||||||
Please refer to the `Virtual environment`_ documentation for installation best
|
|
||||||
practices. If not using a virtual environment, please consider passing the
|
|
||||||
widely recommended `'--user' flag`_ when invoking ``pip``.
|
|
||||||
|
|
||||||
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
|
|
||||||
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site
|
|
||||||
|
|
||||||
.. code-block:: bash
|
|
||||||
|
|
||||||
$ pip install 'molecule[ec2]'
|
|
@ -1,124 +0,0 @@
|
|||||||
---
|
|
||||||
- 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: centos
|
|
||||||
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_iptables
|
|
||||||
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: Delete remote keypair
|
|
||||||
ec2_key:
|
|
||||||
name: "{{ keypair_name }}"
|
|
||||||
state: absent
|
|
||||||
|
|
||||||
- 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 }}"
|
|
||||||
volumes:
|
|
||||||
- device_name: /dev/sda1
|
|
||||||
volume_type: gp2
|
|
||||||
volume_size: 8
|
|
||||||
delete_on_termination: yes
|
|
||||||
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
|
|
@ -1,47 +0,0 @@
|
|||||||
---
|
|
||||||
- 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
|
|
@ -1,26 +0,0 @@
|
|||||||
---
|
|
||||||
dependency:
|
|
||||||
name: galaxy
|
|
||||||
driver:
|
|
||||||
name: ec2
|
|
||||||
platforms:
|
|
||||||
- name: centos-7-iptables
|
|
||||||
image: ami-04cf43aca3e6f3de3
|
|
||||||
instance_type: t2.micro
|
|
||||||
vpc_subnet_id: subnet-9b6896f1
|
|
||||||
lint:
|
|
||||||
name: yamllint
|
|
||||||
enabled: False
|
|
||||||
provisioner:
|
|
||||||
name: ansible
|
|
||||||
lint:
|
|
||||||
name: ansible-lint
|
|
||||||
enabled: False
|
|
||||||
verifier:
|
|
||||||
name: testinfra
|
|
||||||
lint:
|
|
||||||
name: flake8
|
|
||||||
options:
|
|
||||||
max-line-length: 120
|
|
||||||
options:
|
|
||||||
sudo: True
|
|
@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Converge
|
|
||||||
hosts: all
|
|
||||||
|
|
||||||
pre_tasks:
|
|
||||||
- name: Add symlink for iptables
|
|
||||||
file:
|
|
||||||
src: /usr/sbin/iptables
|
|
||||||
dest: /usr/bin/iptables
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
state: link
|
|
||||||
become: True
|
|
||||||
become_user: root
|
|
||||||
|
|
||||||
roles:
|
|
||||||
- role: xoxys.iptables
|
|
@ -1,9 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Prepare
|
|
||||||
hosts: all
|
|
||||||
gather_facts: false
|
|
||||||
tasks:
|
|
||||||
- name: Install python for Ansible
|
|
||||||
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-zipstream)
|
|
||||||
become: true
|
|
||||||
changed_when: false
|
|
@ -1,34 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
import testinfra.utils.ansible_runner
|
|
||||||
|
|
||||||
import warnings
|
|
||||||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
||||||
|
|
||||||
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
|
||||||
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
|
||||||
|
|
||||||
|
|
||||||
def test_iptables_is_installed(host):
|
|
||||||
iptables = host.package("iptables")
|
|
||||||
assert iptables.is_installed
|
|
||||||
|
|
||||||
|
|
||||||
def test_iptables_running_and_enabled(host):
|
|
||||||
iptables = host.service("iptables")
|
|
||||||
assert iptables.is_running
|
|
||||||
assert iptables.is_enabled
|
|
||||||
|
|
||||||
|
|
||||||
def test_iptables_default_rules(host):
|
|
||||||
defaults = [
|
|
||||||
'-P INPUT ACCEPT',
|
|
||||||
'-A INPUT -m state --state RELATED,ESTABLISHED -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
|
|
||||||
'-A INPUT -i lo -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
|
|
||||||
'-A INPUT -p icmp -m icmp --icmp-type 8 -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
|
|
||||||
'-A INPUT -p tcp -m tcp --dport 22 -m comment --comment "ansible[iptables_default_head]" -j ACCEPT',
|
|
||||||
'-A INPUT -m comment --comment "ansible[iptables_default_tail]" -j REJECT --reject-with icmp-port-unreachable'
|
|
||||||
]
|
|
||||||
|
|
||||||
rules = host.iptables.rules("filter", "INPUT")
|
|
||||||
assert defaults == rules
|
|
Loading…
Reference in New Issue
Block a user