diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f81f52b --- /dev/null +++ b/.travis.yml @@ -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/ diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..b317f35 --- /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 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 diff --git a/molecule/default/INSTALL.rst b/molecule/default/INSTALL.rst new file mode 100644 index 0000000..6a44bde --- /dev/null +++ b/molecule/default/INSTALL.rst @@ -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]' diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..92e1be7 --- /dev/null +++ b/molecule/default/molecule.yml @@ -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 diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml new file mode 100644 index 0000000..e6b16db --- /dev/null +++ b/molecule/default/playbook.yml @@ -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 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/roles/scm/tasks/cms.yml b/roles/scm/tasks/cms.yml index 242731d..eb8f5dc 100644 --- a/roles/scm/tasks/cms.yml +++ b/roles/scm/tasks/cms.yml @@ -6,12 +6,8 @@ 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) @@ -19,7 +15,7 @@ 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 }}" @@ -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 @@ -48,6 +43,6 @@ register: start_resp failed_when: "'startTime' not in start_resp.content" -- debug: +- debug: var: start_resp verbosity: 1