diff options
Diffstat (limited to 'ansible')
58 files changed, 566 insertions, 164 deletions
diff --git a/ansible/group_vars/infrastructure.yml b/ansible/group_vars/infrastructure.yml index 66a00b5f..08a25919 100755 --- a/ansible/group_vars/infrastructure.yml +++ b/ansible/group_vars/infrastructure.yml @@ -3,8 +3,6 @@ vnc_passwd: samsung simulated_hosts: git: - gerrit.onap.org - - git.rancher.io - - github.com http: - git.onap.org - nexus.onap.org @@ -16,6 +14,7 @@ simulated_hosts: nexus: - docker.elastic.co - docker.io + - index.docker.io - gcr.io - k8s.gcr.io - nexus.{{ ansible_nodename }} diff --git a/ansible/roles/application/defaults/main.yml b/ansible/roles/application/defaults/main.yml index 84fffeca..2ae668ac 100644 --- a/ansible/roles/application/defaults/main.yml +++ b/ansible/roles/application/defaults/main.yml @@ -11,3 +11,5 @@ helm_extra_install_options: app_skip_helm_override: false app_helm_override_role: application-override app_helm_override_file: "{{ app_data_path }}/override.yaml" +helm_overide_files: + - "{{ app_helm_override_file }}" diff --git a/ansible/roles/application/tasks/install.yml b/ansible/roles/application/tasks/install.yml index bdf6e511..003631d7 100644 --- a/ansible/roles/application/tasks/install.yml +++ b/ansible/roles/application/tasks/install.yml @@ -71,7 +71,7 @@ {{ app_helm_release_name }} {{ helm_repository_name }}/{{ app_helm_chart_name }} --namespace {{ app_kubernetes_namespace }} - {{ '' if app_skip_helm_override else '-f ' + app_helm_override_file }} + {% if not app_skip_helm_override %} {% for arg in helm_overide_files %} {{ '-f ' + arg }} {% endfor %} {% endif %} {% for arg in helm_extra_install_options %} {{ arg.opt }} {% endfor %} changed_when: true # when executed its a changed type of action register: helm_install diff --git a/ansible/roles/dns/handlers/main.yml b/ansible/roles/dns/handlers/main.yml index cd1e4b47..3d7570f5 100644 --- a/ansible/roles/dns/handlers/main.yml +++ b/ansible/roles/dns/handlers/main.yml @@ -2,6 +2,7 @@ - name: Run dns server container docker_container: name: dns-server + network_mode: host image: "{{ dns_server_image }}" command: -H /simulated_hosts --log-facility=- --dns-loop-detect capabilities: NET_ADMIN diff --git a/ansible/roles/helm/.yamllint b/ansible/roles/helm/.yamllint new file mode 100644 index 00000000..ad0be760 --- /dev/null +++ b/ansible/roles/helm/.yamllint @@ -0,0 +1,11 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable diff --git a/ansible/roles/helm/molecule/default/molecule.yml b/ansible/roles/helm/molecule/default/molecule.yml new file mode 100644 index 00000000..869f87f6 --- /dev/null +++ b/ansible/roles/helm/molecule/default/molecule.yml @@ -0,0 +1,32 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: infrastructure-server + image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} + pre_build_image: True + privileged: true + override_command: False + groups: + - infrastructure +provisioner: + name: ansible + lint: + name: ansible-lint + env: + ANSIBLE_ROLES_PATH: ../../../../test/roles + ANSIBLE_LIBRARY: ../../../../library + inventory: + group_vars: + all: + app_name: onap + app_data_path: "/opt/{{ app_name }}" + helm_bin_dir: /usr/local/bin +verifier: + name: testinfra + lint: + name: flake8 diff --git a/ansible/roles/helm/molecule/default/playbook.yml b/ansible/roles/helm/molecule/default/playbook.yml new file mode 100644 index 00000000..2705b165 --- /dev/null +++ b/ansible/roles/helm/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - helm diff --git a/ansible/roles/helm/molecule/default/prepare.yml b/ansible/roles/helm/molecule/default/prepare.yml new file mode 100644 index 00000000..8a149b89 --- /dev/null +++ b/ansible/roles/helm/molecule/default/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare for helm tests + hosts: all + roles: + - prepare-helm diff --git a/ansible/roles/helm/molecule/default/tests/test_default.py b/ansible/roles/helm/molecule/default/tests/test_default.py new file mode 100644 index 00000000..2395183b --- /dev/null +++ b/ansible/roles/helm/molecule/default/tests/test_default.py @@ -0,0 +1,11 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_helm(host): + assert host.file('/usr/local/bin/helm').exists + assert host.run('helm').rc != 127 diff --git a/ansible/roles/kubectl/.yamllint b/ansible/roles/kubectl/.yamllint new file mode 100644 index 00000000..ad0be760 --- /dev/null +++ b/ansible/roles/kubectl/.yamllint @@ -0,0 +1,11 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable diff --git a/ansible/roles/kubectl/molecule/default/molecule.yml b/ansible/roles/kubectl/molecule/default/molecule.yml new file mode 100644 index 00000000..bffb29e6 --- /dev/null +++ b/ansible/roles/kubectl/molecule/default/molecule.yml @@ -0,0 +1,31 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: infrastructure-server + image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} + pre_build_image: True + privileged: true + override_command: False + groups: + - infrastructure +provisioner: + name: ansible + lint: + name: ansible-lint + env: + ANSIBLE_ROLES_PATH: ../../../../test/roles + ANSIBLE_LIBRARY: ../../../../library + inventory: + group_vars: + all: + app_name: onap + app_data_path: "/opt/{{ app_name }}" +verifier: + name: testinfra + lint: + name: flake8 diff --git a/ansible/roles/kubectl/molecule/default/playbook.yml b/ansible/roles/kubectl/molecule/default/playbook.yml new file mode 100644 index 00000000..ab9c08a8 --- /dev/null +++ b/ansible/roles/kubectl/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - kubectl diff --git a/ansible/roles/kubectl/molecule/default/prepare.yml b/ansible/roles/kubectl/molecule/default/prepare.yml new file mode 100644 index 00000000..ec17626a --- /dev/null +++ b/ansible/roles/kubectl/molecule/default/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare for kubectl tests + hosts: all + roles: + - prepare-kubectl diff --git a/ansible/roles/kubectl/molecule/default/tests/test_default.py b/ansible/roles/kubectl/molecule/default/tests/test_default.py new file mode 100644 index 00000000..4f799b95 --- /dev/null +++ b/ansible/roles/kubectl/molecule/default/tests/test_default.py @@ -0,0 +1,11 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_kubectl(host): + assert host.file('/usr/local/bin/kubectl').exists + assert host.run('kubectl').rc != 127 diff --git a/ansible/roles/nfs/molecule/default/molecule.yml b/ansible/roles/nfs/molecule/default/molecule.yml index 7bacf3c4..a8ca6a30 100644 --- a/ansible/roles/nfs/molecule/default/molecule.yml +++ b/ansible/roles/nfs/molecule/default/molecule.yml @@ -19,7 +19,7 @@ platforms: - name: nfs-net volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro - - ${HOME}/data:/dockerdata-nfs:rw + - /dockerdata-nfs - name: kubernetes-node-2 image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} diff --git a/ansible/roles/nginx/.yamllint b/ansible/roles/nginx/.yamllint new file mode 100644 index 00000000..ad0be760 --- /dev/null +++ b/ansible/roles/nginx/.yamllint @@ -0,0 +1,11 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable diff --git a/ansible/roles/nginx/defaults/main.yml b/ansible/roles/nginx/defaults/main.yml index 260de9bf..8bf44197 100644 --- a/ansible/roles/nginx/defaults/main.yml +++ b/ansible/roles/nginx/defaults/main.yml @@ -4,7 +4,7 @@ simulated_hosts: http: nexus: all_simulated_hosts: - "{{ simulated_hosts.git + simulated_hosts.http + simulated_hosts.nexus }}" + "{{ simulated_hosts.git + simulated_hosts.http + simulated_hosts.nexus }}" nginx: ports: diff --git a/ansible/roles/nginx/molecule/default/cleanup.yml b/ansible/roles/nginx/molecule/default/cleanup.yml new file mode 100644 index 00000000..9870a553 --- /dev/null +++ b/ansible/roles/nginx/molecule/default/cleanup.yml @@ -0,0 +1,6 @@ +--- +- name: Cleanup + hosts: all + ignore_unreachable: true + roles: + - cleanup-nginx diff --git a/ansible/roles/nginx/molecule/default/molecule.yml b/ansible/roles/nginx/molecule/default/molecule.yml new file mode 100644 index 00000000..63c47724 --- /dev/null +++ b/ansible/roles/nginx/molecule/default/molecule.yml @@ -0,0 +1,30 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: infrastructure-server + image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} + pre_build_image: true + privileged: true + override_command: false + volumes: + - /var/lib/docker + groups: + - infrastructure +provisioner: + name: ansible + env: + ANSIBLE_ROLES_PATH: ../../../../test/roles + inventory: + links: + group_vars: ../../../../group_vars + lint: + name: ansible-lint +verifier: + name: testinfra + lint: + name: flake8 diff --git a/ansible/roles/nginx/molecule/default/playbook.yml b/ansible/roles/nginx/molecule/default/playbook.yml new file mode 100644 index 00000000..431bb666 --- /dev/null +++ b/ansible/roles/nginx/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - nginx diff --git a/ansible/roles/nginx/molecule/default/prepare.yml b/ansible/roles/nginx/molecule/default/prepare.yml new file mode 100644 index 00000000..5c6ff5d8 --- /dev/null +++ b/ansible/roles/nginx/molecule/default/prepare.yml @@ -0,0 +1,8 @@ +--- +- name: Prepare + hosts: all + vars_files: + - ../../../../roles/nginx/defaults/main.yml + roles: + - prepare-docker-dind + - prepare-nginx diff --git a/ansible/roles/rke/.yamllint b/ansible/roles/rke/.yamllint new file mode 100644 index 00000000..ad0be760 --- /dev/null +++ b/ansible/roles/rke/.yamllint @@ -0,0 +1,11 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable diff --git a/ansible/roles/rke/molecule/default/destroy.yml b/ansible/roles/rke/molecule/default/destroy.yml new file mode 100644 index 00000000..591da82e --- /dev/null +++ b/ansible/roles/rke/molecule/default/destroy.yml @@ -0,0 +1,34 @@ +--- +- 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: + - name: Destroy molecule instance(s) + docker_container: + name: "{{ item.name }}" + docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}" + state: absent + force_kill: "{{ item.force_kill | default(true) }}" + # Modification: we want to clean up old volumes. + keep_volumes: false + register: server + with_items: "{{ molecule_yml.platforms }}" + async: 7200 + poll: 0 + + - name: Wait for instance(s) deletion to complete + async_status: + jid: "{{ item.ansible_job_id }}" + register: docker_jobs + until: docker_jobs.finished + retries: 300 + with_items: "{{ server.results }}" + + - name: Delete docker network(s) + docker_network: + name: "{{ item }}" + docker_host: "{{ item.docker_host | default(lookup('env', 'DOCKER_HOST') or 'unix://var/run/docker.sock') }}" + state: absent + with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}" diff --git a/ansible/roles/rke/molecule/default/molecule.yml b/ansible/roles/rke/molecule/default/molecule.yml new file mode 100644 index 00000000..e8e5ad76 --- /dev/null +++ b/ansible/roles/rke/molecule/default/molecule.yml @@ -0,0 +1,78 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: infrastructure-server + image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} + pre_build_image: true + privileged: true + override_command: false + restart_policy: unless-stopped + volumes: + - /var/lib/kubelet + - /var/lib/docker + env: + container: docker + groups: + - infrastructure + - kubernetes-control-plane + networks: + - name: rke + purge_networks: true + + - name: kubernetes-node-1 + image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} + pre_build_image: true + privileged: true + override_command: false + restart_policy: unless-stopped + env: + container: docker + volumes: + - /var/lib/kubelet + - /var/lib/docker + groups: + - kubernetes + networks: + - name: rke + purge_networks: true + + - name: kubernetes-node-2 + image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} + pre_build_image: true + privileged: true + override_command: false + restart_policy: unless-stopped + env: + container: docker + volumes: + - /var/lib/kubelet + - /var/lib/docker + groups: + - kubernetes + networks: + - name: rke + purge_networks: true + +provisioner: + name: ansible + env: + ANSIBLE_ROLES_PATH: ../../../../test/roles + ANSIBLE_LIBRARY: ../../../../library + inventory: + links: + group_vars: ../../../../group_vars + options: + e: "app_data_path=/opt/onap" + lint: + name: ansible-lint +scenario: + name: default +verifier: + name: testinfra + lint: + name: flake8 diff --git a/ansible/roles/rke/molecule/default/playbook.yml b/ansible/roles/rke/molecule/default/playbook.yml new file mode 100644 index 00000000..09dbfb8e --- /dev/null +++ b/ansible/roles/rke/molecule/default/playbook.yml @@ -0,0 +1,30 @@ +--- +- name: "Set cluster_ip" + hosts: all + tasks: + - name: "Set cluster_ip fact" + set_fact: + cluster_ip: "{{ ansible_default_ipv4.address }}" + +- name: Configure kubernetes cluster (RKE) + hosts: infrastructure + roles: + - role: rke + vars: + mode: config + +- name: Prepare kubernetes nodes (RKE) + hosts: + - kubernetes + - kubernetes-control-plane + roles: + - role: rke + vars: + mode: node + +- name: Deploy kubernetes cluster (RKE) + hosts: infrastructure + roles: + - role: rke + vars: + mode: deploy diff --git a/ansible/roles/rke/molecule/default/prepare.yml b/ansible/roles/rke/molecule/default/prepare.yml new file mode 100644 index 00000000..6bad2b80 --- /dev/null +++ b/ansible/roles/rke/molecule/default/prepare.yml @@ -0,0 +1,15 @@ +--- +- name: "Prepare hosts" + hosts: all + roles: + - role: prepare-rke + vars: + mode: all + - prepare-docker-dind + +- name: "Infra specific preparations" + hosts: infrastructure + roles: + - role: prepare-rke + vars: + mode: infra diff --git a/ansible/roles/rke/molecule/default/tests/test_controlplane.py b/ansible/roles/rke/molecule/default/tests/test_controlplane.py new file mode 100644 index 00000000..0bfbca2d --- /dev/null +++ b/ansible/roles/rke/molecule/default/tests/test_controlplane.py @@ -0,0 +1,14 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts( + 'kubernetes-control-plane') + + +@pytest.mark.parametrize('container_name', [ + 'kube-apiserver', 'kube-controller-manager', 'kube-scheduler', 'kubelet']) +def test_container_running(host, container_name): + assert host.docker(container_name).is_running diff --git a/ansible/roles/rke/molecule/default/tests/test_infrastructure.py b/ansible/roles/rke/molecule/default/tests/test_infrastructure.py new file mode 100644 index 00000000..9ba11d6e --- /dev/null +++ b/ansible/roles/rke/molecule/default/tests/test_infrastructure.py @@ -0,0 +1,56 @@ +import os +import pytest +import json + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('infrastructure') + + +@pytest.mark.parametrize('filename', [ + '/root/.kube/config', + '/opt/onap/cluster/cluster.yml', + '/opt/onap/cluster/cluster.rkestate']) +def test_file_existence(host, filename): + assert host.file(filename).exists + + +def test_rke_in_path(host): + assert host.find_command('rke') == '/usr/local/bin/rke' + + +def test_rke_version_works(host): + # Note that we need to cd to the cluster data dir first, really. + assert host.run('cd /opt/onap/cluster && rke version').rc == 0 + + +def test_nodes_ready(host): + # Retrieve all node names. + nodecmdres = host.run('kubectl get nodes -o name') + assert nodecmdres.rc == 0 + nodes = nodecmdres.stdout.split('\n') + for node in nodes: + assert host.run( + 'kubectl wait --timeout=0 --for=condition=ready ' + node).rc == 0 + + +def test_pods_ready(host): + # Retrieve all pods from all namespaces. + # Because we need pod and namespace name, we get full json representation. + podcmdres = host.run('kubectl get pods --all-namespaces -o json') + assert podcmdres.rc == 0 + pods = json.loads(podcmdres.stdout)['items'] + for pod in pods: + # Each pod may be either created by a job or not. + # In job case they should already be completed + # when we are here so we ignore them. + namespace = pod['metadata']['namespace'] + podname = pod['metadata']['name'] + condition = 'Ready' + if len(pod['metadata']['ownerReferences']) == 1 and pod[ + 'metadata']['ownerReferences'][0]['kind'] == 'Job': + continue + assert host.run( + 'kubectl wait --timeout=120s --for=condition=' + condition + ' -n ' + + namespace + ' pods/' + podname).rc == 0 diff --git a/ansible/roles/rke/molecule/default/tests/test_kubernetes.py b/ansible/roles/rke/molecule/default/tests/test_kubernetes.py new file mode 100644 index 00000000..887494fa --- /dev/null +++ b/ansible/roles/rke/molecule/default/tests/test_kubernetes.py @@ -0,0 +1,13 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('kubernetes') + + +@pytest.mark.parametrize('container_name', [ + 'etcd', 'kubelet', 'kube-proxy']) +def test_container_running(host, container_name): + assert host.docker(container_name).is_running diff --git a/ansible/roles/rke/tasks/rke_config.yml b/ansible/roles/rke/tasks/rke_config.yml index 4112e107..9dc0d8c6 100644 --- a/ansible/roles/rke/tasks/rke_config.yml +++ b/ansible/roles/rke/tasks/rke_config.yml @@ -37,6 +37,7 @@ template: src: cluster.yml.j2 dest: "{{ cluster_config_dir }}/cluster.yml" + register: cluster_yml - name: Prepare rke addon manifest (dashboard) template: diff --git a/ansible/roles/rke/tasks/rke_deploy.yml b/ansible/roles/rke/tasks/rke_deploy.yml index 9983d08a..7b36f55d 100644 --- a/ansible/roles/rke/tasks/rke_deploy.yml +++ b/ansible/roles/rke/tasks/rke_deploy.yml @@ -1,8 +1,17 @@ --- +- name: "Check if rke is deployed" + command: "rke version" + args: + chdir: "{{ cluster_config_dir }}" + failed_when: false + changed_when: false + register: rke_deployed + - name: Run rke up command: "{{ rke_bin_dir }}/rke up --config cluster.yml" args: chdir: "{{ cluster_config_dir }}" + when: rke_deployed.rc != 0 or cluster_yml.changed # noqa 503 - name: Ensure .kube directory is present file: diff --git a/ansible/test/play-infrastructure/molecule/default/cleanup.yml b/ansible/test/play-infrastructure/molecule/default/cleanup.yml new file mode 100644 index 00000000..9870a553 --- /dev/null +++ b/ansible/test/play-infrastructure/molecule/default/cleanup.yml @@ -0,0 +1,6 @@ +--- +- name: Cleanup + hosts: all + ignore_unreachable: true + roles: + - cleanup-nginx diff --git a/ansible/test/play-resources/molecule/default/cleanup.yml b/ansible/test/play-resources/molecule/default/cleanup.yml deleted file mode 100644 index e0c0b624..00000000 --- a/ansible/test/play-resources/molecule/default/cleanup.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -- name: Cleanup data from instance (doing it from hosts requires root access). - hosts: resources - gather_facts: false - ignore_unreachable: true - pre_tasks: - - name: Find files and dirs to delete - find: - paths: /data/ # Only deleting content not dir itself as we get "Device or resource busy" error as it's mounted to container doing the deletion - patterns: "*" - recurse: true - file_type: any - register: files_to_delete - - name: Make file/dir path list - set_fact: - to_delete_paths: "{{ to_delete_paths | default([]) + [item.path] }}" - loop: "{{ files_to_delete.files }}" - when: files_to_delete.files is defined - roles: - - role: cleanup-directories - vars: - directories_files_list_to_remove: "{{ to_delete_paths }}" - when: to_delete_paths is defined diff --git a/ansible/test/play-resources/molecule/default/playbook.yml b/ansible/test/play-resources/molecule/default/playbook.yml index 50ba233a..096077a2 100644 --- a/ansible/test/play-resources/molecule/default/playbook.yml +++ b/ansible/test/play-resources/molecule/default/playbook.yml @@ -1,6 +1,8 @@ --- -- name: Test resource transfer with ssh +- name: Initialize hosts: all - roles: - - setup - - resource-data + tasks: + - name: Include variables + include_vars: vars.yml + +- import_playbook: ../../../../resources.yml diff --git a/ansible/test/play-resources/molecule/default/prepare.yml b/ansible/test/play-resources/molecule/default/prepare.yml index a4436001..5c8ae654 100644 --- a/ansible/test/play-resources/molecule/default/prepare.yml +++ b/ansible/test/play-resources/molecule/default/prepare.yml @@ -2,4 +2,7 @@ - name: Prepare resource-data hosts: all roles: + - setup - prepare-resource-data + vars_files: + - vars.yml diff --git a/ansible/test/play-resources/molecule/default/group_vars/all.yml b/ansible/test/play-resources/molecule/default/vars.yml index 558eacb2..46ab3e04 100644 --- a/ansible/test/play-resources/molecule/default/group_vars/all.yml +++ b/ansible/test/play-resources/molecule/default/vars.yml @@ -1,5 +1,5 @@ --- -app_data_path: /opt/myleculeapp +app_data_path: /opt/moleculeapp aux_data_path: "{{ app_data_path }}/runtime_images_source_dir" resources_dir: /data resources_filename: resources_package.tar diff --git a/ansible/test/play-resources/molecule/nfs/molecule.yml b/ansible/test/play-resources/molecule/nfs/molecule.yml index ffaabb07..11726396 100644 --- a/ansible/test/play-resources/molecule/nfs/molecule.yml +++ b/ansible/test/play-resources/molecule/nfs/molecule.yml @@ -13,7 +13,7 @@ platforms: override_command: false volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro - - ${HOME}/data:/data:rw # mount fs from host to get nfs exportfs task working + - /data groups: - resources networks: @@ -32,13 +32,8 @@ platforms: - name: resource-data provisioner: name: ansible - playbooks: - cleanup: ../default/cleanup.yml env: ANSIBLE_ROLES_PATH: ../../../../roles:../../../roles - inventory: - links: - group_vars: ../default/group_vars lint: name: ansible-lint verifier: diff --git a/ansible/test/play-resources/molecule/nfs/playbook.yml b/ansible/test/play-resources/molecule/nfs/playbook.yml index 88440116..096077a2 100644 --- a/ansible/test/play-resources/molecule/nfs/playbook.yml +++ b/ansible/test/play-resources/molecule/nfs/playbook.yml @@ -1,8 +1,8 @@ --- -- name: Test resource transfer with nfs +- name: Initialize hosts: all - roles: - - setup - - role: resource-data - vars: - resources_on_nfs: true + tasks: + - name: Include variables + include_vars: vars.yml + +- import_playbook: ../../../../resources.yml diff --git a/ansible/test/play-resources/molecule/nfs/prepare.yml b/ansible/test/play-resources/molecule/nfs/prepare.yml index d381ba77..2276f2e8 100644 --- a/ansible/test/play-resources/molecule/nfs/prepare.yml +++ b/ansible/test/play-resources/molecule/nfs/prepare.yml @@ -1,7 +1,7 @@ --- -- name: Prepare resource-data +- name: Prepare hosts: all roles: - - role: prepare-resource-data - vars: - resources_on_nfs: true + - prepare-resource-data + vars_files: + - vars.yml diff --git a/ansible/test/play-resources/molecule/nfs/vars.yml b/ansible/test/play-resources/molecule/nfs/vars.yml new file mode 100644 index 00000000..2cc4d258 --- /dev/null +++ b/ansible/test/play-resources/molecule/nfs/vars.yml @@ -0,0 +1,7 @@ +--- +app_data_path: /opt/moleculeapp +aux_data_path: "{{ app_data_path }}/runtime_images_source_dir" +resources_on_nfs: true +resources_dir: /data +resources_filename: resources_package.tar +aux_resources_filename: aux_resources_package.tar diff --git a/ansible/test/roles/cleanup-containers/tasks/main.yml b/ansible/test/roles/cleanup-containers/tasks/main.yml deleted file mode 100644 index 3a800c9e..00000000 --- a/ansible/test/roles/cleanup-containers/tasks/main.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -- name: Remove containers - docker_container: - name: "{{ item }}" - state: absent - loop: "{{ container_list }}" diff --git a/ansible/test/roles/cleanup-directories/tasks/main.yml b/ansible/test/roles/cleanup-directories/tasks/main.yml deleted file mode 100644 index 8e79ea0c..00000000 --- a/ansible/test/roles/cleanup-directories/tasks/main.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: Remove directories/files - file: - path: "{{ item }}" - state: absent - become: true - loop: "{{ directories_files_list_to_remove }}" diff --git a/ansible/test/roles/cleanup-nginx/tasks/main.yml b/ansible/test/roles/cleanup-nginx/tasks/main.yml new file mode 100644 index 00000000..94517519 --- /dev/null +++ b/ansible/test/roles/cleanup-nginx/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: Remove saved nginx docker image + delegate_to: localhost + file: + path: /tmp/nginx.tar + state: absent diff --git a/ansible/test/roles/cleanup-rancher/tasks/main.yml b/ansible/test/roles/cleanup-rancher/tasks/main.yml deleted file mode 100644 index 21b02988..00000000 --- a/ansible/test/roles/cleanup-rancher/tasks/main.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -# Remove containers spawned by Rancher Agent -- name: Get list of containers spawned by Rancher Agent - docker_list_containers: - label_name: "{{ item.label }}" - label_value: "{{ item.value }}" - loop: "{{ container_list_by_label }}" - register: docker_list_containers_var - -- name: set fact # save a list of containers found by previous task to orphaned_containers var - set_fact: orphaned_containers="{{ orphaned_containers|default([]) + item.containers }}" - loop: "{{ docker_list_containers_var.results }}" - -- name: Remove orphaned containers - docker_container: - name: "{{ item }}" - state: absent - loop: "{{ orphaned_containers }}" diff --git a/ansible/test/roles/prepare-docker/tasks/docker-packages.yml b/ansible/test/roles/prepare-docker/tasks/docker-packages.yml deleted file mode 100644 index 8f55c5ce..00000000 --- a/ansible/test/roles/prepare-docker/tasks/docker-packages.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- - -- name: Download docker related packages - command: yumdownloader --destdir="{{ rpm_dir }}" "{{ docker_ce_rpm }}" - args: - creates: "{{ rpm_dir }}/{{ docker_ce_rpm }}" - -- name: Install docker related packages - yum: - name: "{{ rpm_dir + '/' + docker_ce_rpm + '.rpm'}}" diff --git a/ansible/test/roles/prepare-docker/tasks/docker-socket-override.yml b/ansible/test/roles/prepare-docker/tasks/docker-socket-override.yml deleted file mode 100644 index 0cabadf4..00000000 --- a/ansible/test/roles/prepare-docker/tasks/docker-socket-override.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: Create docker.socket systemd dir for override - file: - path: /etc/systemd/system/docker.socket.d - state: directory - -- name: Fake dockerd dependent docker.socket service not to actually listen the docker socket as dockerd is not used in container only docker client - copy: - content: | - [Socket] - ListenStream= - ListenStream=/tmp/fake - dest: /etc/systemd/system/docker.socket.d/override.conf diff --git a/ansible/test/roles/prepare-docker/tasks/enable-repos.yml b/ansible/test/roles/prepare-docker/tasks/enable-repos.yml deleted file mode 100644 index 204bf03d..00000000 --- a/ansible/test/roles/prepare-docker/tasks/enable-repos.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: Enable docker repos back for Molecule testing purposes - copy: - remote_src: yes - src: "{{ item }}" - dest: "{{ (item | splitext)[0] }}" - loop: "{{ docker_needed_repos }}" - -- name: Disable offline repo for molecule testing purposes - lineinfile: - path: "{{ offline_repo_file }}" - regexp: 'enabled = 1' - line: 'enabled = 0' diff --git a/ansible/test/roles/prepare-docker/tasks/main.yml b/ansible/test/roles/prepare-docker/tasks/main.yml deleted file mode 100644 index e7d87061..00000000 --- a/ansible/test/roles/prepare-docker/tasks/main.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: Check repositories - stat: - path: "{{ item }}" - loop: "{{ docker_needed_repos + [offline_repo_file] }}" - register: repos - -- name: Set fact for offline repos created - set_fact: - offline_repo_created: "{{ (repos.results | map(attribute='stat.exists') | list) is all }}" - -- debug: - var: offline_repo_created - -- name: Enable repos back (if package-repository role already setup offline onap repo) for molecule testing purposes to install docker - include_tasks: enable-repos.yml - when: offline_repo_created - -- name: Prepare docker repos normally - include_tasks: prepare-docker-repos.yml - when: not offline_repo_created diff --git a/ansible/test/roles/prepare-docker/tasks/prepare-docker-repos.yml b/ansible/test/roles/prepare-docker/tasks/prepare-docker-repos.yml deleted file mode 100644 index 01ea72c3..00000000 --- a/ansible/test/roles/prepare-docker/tasks/prepare-docker-repos.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -- name: Install Docker-CE repo - yum_repository: - name: docker-ce - description: Docker-ce YUM repo - baseurl: https://download.docker.com/linux/centos/7/x86_64/stable/ - gpgcheck: true - gpgkey: https://download.docker.com/linux/centos/gpg - -- name: Create rpm dir - file: - path: "{{ rpm_dir }}" - state: directory - -- name: Handle docker-ce packages - import_tasks: docker-packages.yml - -- name: Fake dockerd on container - import_tasks: docker-socket-override.yml - when: ansible_env.container == 'docker' diff --git a/ansible/test/roles/prepare-docker/vars/main.yml b/ansible/test/roles/prepare-docker/vars/main.yml deleted file mode 100644 index bcd7f365..00000000 --- a/ansible/test/roles/prepare-docker/vars/main.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -docker_needed_repos: - - /etc/yum.repos.d/CentOS-Base.repo.disabled - - /etc/yum.repos.d/docker-ce.repo.disabled -offline_repo_file: /etc/yum.repos.d/onap.repo -rpm_dir: /root/rpm -docker_ce_rpm: docker-ce-18.09.5-3.el7.x86_64 diff --git a/ansible/test/roles/prepare-helm/defaults/main.yml b/ansible/test/roles/prepare-helm/defaults/main.yml new file mode 100644 index 00000000..8ab9ed3a --- /dev/null +++ b/ansible/test/roles/prepare-helm/defaults/main.yml @@ -0,0 +1,3 @@ +--- +# Helm version to download. +helm_version: 2.12.3 diff --git a/ansible/test/roles/prepare-helm/tasks/main.yml b/ansible/test/roles/prepare-helm/tasks/main.yml new file mode 100644 index 00000000..aa01e281 --- /dev/null +++ b/ansible/test/roles/prepare-helm/tasks/main.yml @@ -0,0 +1,18 @@ +--- +- name: "Ensure {{ app_data_path }}/downloads directory exists" + file: + path: "{{ app_data_path }}/downloads" + recurse: true + state: directory + +- name: "Download and unarchive helm-{{ helm_version }}" + unarchive: + src: "https://get.helm.sh/helm-v{{ helm_version }}-linux-amd64.tar.gz" + dest: "/tmp" + remote_src: true + +- name: "Copy helm binary" + copy: + src: /tmp/linux-amd64/helm + dest: "{{ app_data_path }}/downloads/helm" + remote_src: true diff --git a/ansible/test/roles/prepare-kubectl/defaults/main.yml b/ansible/test/roles/prepare-kubectl/defaults/main.yml new file mode 100644 index 00000000..d4e8ef94 --- /dev/null +++ b/ansible/test/roles/prepare-kubectl/defaults/main.yml @@ -0,0 +1,7 @@ +--- +# Set to false to download kubectl in preparation for kubectl role that +# needs to install it, set to true to immediately install (needed for +# cases where it is used by verification tests of other roles). +kubectl_install: false +# Kubectl version. +kubectl_version: 1.13.5 diff --git a/ansible/test/roles/prepare-kubectl/tasks/main.yml b/ansible/test/roles/prepare-kubectl/tasks/main.yml new file mode 100644 index 00000000..b5631850 --- /dev/null +++ b/ansible/test/roles/prepare-kubectl/tasks/main.yml @@ -0,0 +1,14 @@ +--- +- name: "Ensure {{ app_data_path }} exists" + file: + path: "{{ app_data_path }}/downloads" + state: directory + when: not kubectl_install + +- name: "Install kubectl-{{ kubectl_version }}" + get_url: + url: "https://storage.googleapis.com/kubernetes-release/release/v{{ kubectl_version }}/bin/linux/amd64/kubectl" + dest: "{{ '/usr/local/bin/kubectl' if kubectl_install else app_data_path+'/downloads/kubectl' }}" + # This mode conditional allows checking if kubectl role, when installing kubectl, correctly + # adds executable bit (bonus). + mode: "{{ 0755 if kubectl_install else omit }}" diff --git a/ansible/test/roles/prepare-rke/defaults/main.yml b/ansible/test/roles/prepare-rke/defaults/main.yml new file mode 100644 index 00000000..2cf85635 --- /dev/null +++ b/ansible/test/roles/prepare-rke/defaults/main.yml @@ -0,0 +1,5 @@ +--- +#The rke version. +rke_version: 0.2.0 +#The kubectl version. +kubectl_version: 1.13.5 diff --git a/ansible/test/roles/prepare-rke/tasks/all.yml b/ansible/test/roles/prepare-rke/tasks/all.yml new file mode 100644 index 00000000..d4b67c1f --- /dev/null +++ b/ansible/test/roles/prepare-rke/tasks/all.yml @@ -0,0 +1,6 @@ +#This is needed because login from non root is blocked by default. +- name: "Allow non root logins" + service: + name: systemd-user-sessions + state: started + diff --git a/ansible/test/roles/prepare-rke/tasks/infra.yml b/ansible/test/roles/prepare-rke/tasks/infra.yml new file mode 100644 index 00000000..55ab7f16 --- /dev/null +++ b/ansible/test/roles/prepare-rke/tasks/infra.yml @@ -0,0 +1,16 @@ +--- +- name: "Ensure {{ app_data_path }} exists" + file: + path: "{{ app_data_path }}/downloads" + state: directory + +- name: "Install rke-{{ rke_version }}" + get_url: + url: "https://github.com/rancher/rke/releases/download/v{{ rke_version }}/rke_linux-amd64" + dest: "{{ app_data_path }}/downloads/rke" + +- name: "Install kubectl-{{ kubectl_version }}" + get_url: + url: "https://storage.googleapis.com/kubernetes-release/release/v{{ kubectl_version }}/bin/linux/amd64/kubectl" + dest: "/usr/local/bin/kubectl" + mode: 0755 diff --git a/ansible/test/roles/prepare-rke/tasks/main.yml b/ansible/test/roles/prepare-rke/tasks/main.yml new file mode 100644 index 00000000..210c9b57 --- /dev/null +++ b/ansible/test/roles/prepare-rke/tasks/main.yml @@ -0,0 +1,2 @@ +--- +- include_tasks: "{{ mode }}.yml" |