Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
sudo: required

language: python

services:
- docker

install:
# molecule version >v2.22 required for compatibility with ansible >2.8
- pip install molecule==2.22
# Note: ansible 2.9.0 is buggy, see the README
#- pip install ansible==2.8.2
- pip install ansible==2.9.1
- pip install docker
# 'jmespath' required by the 'cdh' role (that uses the 'json_query' filter)
- pip install jmespath
script:
- molecule test
# TODO test more scenarios (multi-node !?)
#- molecule test --scenario-name xxx

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
14 changes: 14 additions & 0 deletions molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -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 iproute2 && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash iproute && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash iproute && 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 iproute2 && 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 iproute2 && xbps-remove -O; fi
22 changes: 22 additions & 0 deletions molecule/default/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*******
Docker driver installation guide
*******

Requirements
============

* Docker Engine

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[docker]'
84 changes: 84 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
# Molecule config for a single-node CDH cluster
#
# Notes:
# - Linters are set enabled=false because the roles currently contains many lint warnings
# - The 'destroy' action is commented out to avoid accidentally destroying your molecule cluster
#
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
# Using geerlingguy's image that provides centos7 with ansible AND systemd
platforms:
- name: "${MOLECULE_DISTRO:-centos7}-cdh01.local"
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
pre_build_image: True
privileged: True
volume_mounts:
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
command: "/usr/sbin/init"
groups:
# following groups required by the role's site.yml playbook
- cdh_servers
- db_server
- scm_server # group used during 'scm' role
- krb5_server
# networks:
# - name: molecule_cdh
# network_mode: bridge
# Host networking did not work on my Macbook (it hang at task waiting for the Ambari Agents registration)
#network_mode: host
published_ports:
# Cloudera Manager
- 0.0.0.0:7180:7180/tcp
# YARN
- 0.0.0.0:8088:8088/tcp
# HDFS
- 0.0.0.0:50070:50070/tcp
- 0.0.0.0:50075:50075/tcp

provisioner:
name: ansible
config_options:
#TODO enable later
# defaults:
# gathering: smart
# fact_caching: jsonfile
# fact_caching_connection: /tmp/facts_cache
ssh_connection:
pipelining: True

options:
diff: true
v: True
inventory:
group_vars:
# Note: 'all' inventory group_vars will be overriden by the 'all' playbook group_vars, but not specific groups
cdh_servers:
java_installation_strategy: package
# assigning templates to our host:
host_template: HostTemplate-Edge
role_ref_names: HDFS-HTTPFS-1
lint:
name: ansible-lint
scenario:
name: default
test_sequence:
# - lint
#- destroy
- dependency
- syntax
- create
- prepare
- converge
#- idempotence
# - side_effect
- verify
#- destroy
verifier:
name: testinfra
lint:
name: flake8
10 changes: 10 additions & 0 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Pre-reqs
hosts: all
tasks:
- debug:
msg: "Pre-reqs tasks if needed"

- name: Converge
# Note: To override the repo's "playbook group_vars" it's easier to use a "vars:" block here, as inventory vars have lower precedence!
import_playbook: ../../site.yml
14 changes: 14 additions & 0 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -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'
15 changes: 5 additions & 10 deletions roles/scm/tasks/cms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@
pause:
seconds: 30

# Prepare CMS template
- name: Prepare CMS template
template:
src: "cms_base.j2"
dest: "{{ tmp_dir }}/cms_base.json"
delegate_to: localhost
- set_fact:
cms_config_json: "{{ lookup('template', 'cms_base.j2', convert_data=False) }}"

# https://cloudera.github.io/cm_api/apidocs/v12/path__cm_service.html#PUT
- name: Setup the Cloudera Management Services (CMS)
uri:
url: "{{ cm_api_url }}/cm/service"
method: PUT
body_format: json
body: "{{ lookup('file', ''+ tmp_dir + '/cms_base.json') }}"
body: "{{ cms_config_json|to_json }}"
status_code: 200,400
force_basic_auth: yes
user: "{{ scm_default_user }}"
Expand All @@ -29,9 +25,8 @@
failed_when:
- "'MGMT' not in cms_resp.content"
- "'CMS instance already exists' not in cms_resp.content"
delegate_to: localhost

- debug:
- debug:
var: cms_resp
verbosity: 1

Expand All @@ -48,6 +43,6 @@
register: start_resp
failed_when: "'startTime' not in start_resp.content"

- debug:
- debug:
var: start_resp
verbosity: 1