summaryrefslogtreecommitdiffstats
path: root/ansible/roles
diff options
context:
space:
mode:
authorJan Benedikt <j.benedikt@partner.samsung.com>2020-02-10 16:29:43 +0100
committerJan Benedikt <j.benedikt@partner.samsung.com>2020-05-18 09:21:52 +0200
commit2c34d1d7a33e34c9984ac78460fd8e7c815024c5 (patch)
tree1bac4c90b3d8f899248919f97af24f4fe31547e8 /ansible/roles
parent17e0a5eacaed7519f13e2c0f19749fb4263fb46a (diff)
Adding Ubuntu support in Ansible - package-repository role
Extending ansible playbooks of ubuntu support. Creating new test with Ubuntu image for Molecule in package-repository role. Issue-ID: OOM-1671 Signed-off-by: Jan Benedikt <j.benedikt@partner.samsung.com> Change-Id: I85d4e6857536fa06c7eb4f4042c1ed64fcbf903e
Diffstat (limited to 'ansible/roles')
-rw-r--r--ansible/roles/package-repository/defaults/main.yml11
-rw-r--r--ansible/roles/package-repository/molecule/default/Dockerfile.j25
-rw-r--r--ansible/roles/package-repository/molecule/default/molecule.yml2
-rw-r--r--ansible/roles/package-repository/molecule/default/tests/test_infrastructure-server.py13
-rw-r--r--ansible/roles/package-repository/molecule/default/tests/test_kubernetes-node-1.py13
-rw-r--r--ansible/roles/package-repository/molecule/ubuntu/molecule.yml51
-rw-r--r--ansible/roles/package-repository/tasks/Debian.yml8
-rw-r--r--ansible/roles/package-repository/tasks/RedHat.yml11
-rw-r--r--ansible/roles/package-repository/tasks/main.yml17
9 files changed, 108 insertions, 23 deletions
diff --git a/ansible/roles/package-repository/defaults/main.yml b/ansible/roles/package-repository/defaults/main.yml
index 0557eda3..97b89bae 100644
--- a/ansible/roles/package-repository/defaults/main.yml
+++ b/ansible/roles/package-repository/defaults/main.yml
@@ -1,8 +1,17 @@
---
+package_type:
+ RedHat: rpm
+ Debian: deb
+repo_patern:
+ RedHat: "*.repo"
+ Debian: "*.list"
+repo_path:
+ RedHat: /etc/yum.repos.d/
+ Debian: /etc/apt/
package_repositories:
- name: "{{ app_name }}"
file: "{{ app_name | lower }}"
description: "{{ app_name | upper }} offline repository"
- baseurl: "{{ 'http://repo.infra-server/rpm' if 'infrastructure' not in group_names else 'file://' + app_data_path + '/pkg/rpm' }}"
+ baseurl: "{{ 'http://repo.infra-server/' + package_type[ansible_os_family] if 'infrastructure' not in group_names else 'file://' + app_data_path + '/pkg/' + package_type[ansible_os_family] }}"
gpgcheck: false
enabled: true
diff --git a/ansible/roles/package-repository/molecule/default/Dockerfile.j2 b/ansible/roles/package-repository/molecule/default/Dockerfile.j2
index 0a605536..b76a6dd7 100644
--- a/ansible/roles/package-repository/molecule/default/Dockerfile.j2
+++ b/ansible/roles/package-repository/molecule/default/Dockerfile.j2
@@ -6,9 +6,12 @@ FROM {{ item.registry.url }}/{{ item.image }}
FROM {{ item.image }}
{% endif %}
-RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
+RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y sudo bash ca-certificates python3-apt && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && 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 && 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 && xbps-remove -O; fi
+
+# Create symlink python3 -> python
+RUN if [ $(command -v apt-get) ]; then ln -s /usr/bin/python3 /usr/bin/python; fi
diff --git a/ansible/roles/package-repository/molecule/default/molecule.yml b/ansible/roles/package-repository/molecule/default/molecule.yml
index df2024d7..7abb08d4 100644
--- a/ansible/roles/package-repository/molecule/default/molecule.yml
+++ b/ansible/roles/package-repository/molecule/default/molecule.yml
@@ -36,8 +36,6 @@ provisioner:
all:
app_name: moleculetestapp
app_data_path: "/opt/{{ app_name }}"
-scenario:
- name: default
verifier:
name: testinfra
options:
diff --git a/ansible/roles/package-repository/molecule/default/tests/test_infrastructure-server.py b/ansible/roles/package-repository/molecule/default/tests/test_infrastructure-server.py
index 9fb1a4f9..5b3fce4d 100644
--- a/ansible/roles/package-repository/molecule/default/tests/test_infrastructure-server.py
+++ b/ansible/roles/package-repository/molecule/default/tests/test_infrastructure-server.py
@@ -7,10 +7,17 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
def test_onap_repo(host):
- fc = host.file('/etc/yum.repos.d/moleculetestapp.repo').content_string
- expected_content = """[moleculetestapp]
+ os = host.system_info.distribution
+ if os == "centos":
+ fc = host.file('/etc/yum.repos.d/moleculetestapp.repo').content_string
+ expected_content = """[moleculetestapp]
baseurl = file:///opt/moleculetestapp/pkg/rpm
enabled = 1
gpgcheck = 0
name = MOLECULETESTAPP offline repository"""
- assert fc == expected_content
+ assert fc == expected_content
+ elif os == "ubuntu":
+ fc = host.file('/etc/apt/sources.list.d/moleculetestapp.list')
+ fc = fc.content_string
+ ec = "deb [trusted=yes] file:///opt/moleculetestapp/pkg/deb ./"
+ assert fc == ec
diff --git a/ansible/roles/package-repository/molecule/default/tests/test_kubernetes-node-1.py b/ansible/roles/package-repository/molecule/default/tests/test_kubernetes-node-1.py
index fda85e8d..c1831f70 100644
--- a/ansible/roles/package-repository/molecule/default/tests/test_kubernetes-node-1.py
+++ b/ansible/roles/package-repository/molecule/default/tests/test_kubernetes-node-1.py
@@ -7,10 +7,17 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
def test_onap_repo(host):
- fc = host.file('/etc/yum.repos.d/moleculetestapp.repo').content_string
- expected_content = """[moleculetestapp]
+ os = host.system_info.distribution
+ if os == "centos":
+ fc = host.file('/etc/yum.repos.d/moleculetestapp.repo').content_string
+ expected_content = """[moleculetestapp]
baseurl = http://repo.infra-server/rpm
enabled = 1
gpgcheck = 0
name = MOLECULETESTAPP offline repository"""
- assert fc == expected_content
+ assert fc == expected_content
+ elif os == "ubuntu":
+ fc = host.file('/etc/apt/sources.list.d/moleculetestapp.list')
+ fc = fc.content_string
+ ec = "deb [trusted=yes] http://repo.infra-server/deb ./"
+ assert fc == ec
diff --git a/ansible/roles/package-repository/molecule/ubuntu/molecule.yml b/ansible/roles/package-repository/molecule/ubuntu/molecule.yml
new file mode 100644
index 00000000..07c2d888
--- /dev/null
+++ b/ansible/roles/package-repository/molecule/ubuntu/molecule.yml
@@ -0,0 +1,51 @@
+---
+dependency:
+ name: galaxy
+driver:
+ name: docker
+lint:
+ name: yamllint
+platforms:
+ - name: infrastructure-server
+ image: ${PLATFORM_DISTRO:-ubuntu}:${ISTRO_VERSION:-18.04}
+ dockerfile: ../default/Dockerfile.j2
+ groups:
+ - infrastructure
+ # By design certain file like /etc/resolv.conf cannot be edited in docker
+ # container. To enable role to "edit" /etc/resolv.conf define value already to same.
+ dns_servers:
+ - 6.5.4.3
+
+ - name: kubernetes-node-1
+ image: ${PLATFORM_DISTRO:-ubuntu}:${ISTRO_VERSION:-18.04}
+ dockerfile: ../default/Dockerfile.j2
+ groups:
+ - kubernetes
+ # By design certain file like /etc/resolv.conf cannot be edited in docker
+ # container. To enable role to "edit" /etc/resolv.conf define value already to same.
+ dns_servers:
+ - 6.5.4.3
+
+provisioner:
+ name: ansible
+ lint:
+ name: ansible-lint
+ playbooks:
+ converge: ../default/playbook.yml
+ inventory:
+ host_vars:
+ infrastructure-server:
+ cluster_ip: 6.5.4.3
+ group_vars:
+ all:
+ app_name: moleculetestapp
+ app_data_path: "/opt/{{ app_name }}"
+scenario:
+ name: ubuntu
+verifier:
+ name: testinfra
+ options:
+ verbose: true
+ lint:
+ name: flake8
+ directory: ../default/tests
diff --git a/ansible/roles/package-repository/tasks/Debian.yml b/ansible/roles/package-repository/tasks/Debian.yml
new file mode 100644
index 00000000..76323eb4
--- /dev/null
+++ b/ansible/roles/package-repository/tasks/Debian.yml
@@ -0,0 +1,8 @@
+---
+- name: Add application offline package repository
+ apt_repository:
+ repo: "deb [trusted=yes] {{ item.baseurl | default('') }} ./"
+ state: "{{ item.state | default('present') }}"
+ filename: "{{ item.file }}"
+ update_cache: false
+ loop: "{{ package_repositories }}"
diff --git a/ansible/roles/package-repository/tasks/RedHat.yml b/ansible/roles/package-repository/tasks/RedHat.yml
new file mode 100644
index 00000000..49b29718
--- /dev/null
+++ b/ansible/roles/package-repository/tasks/RedHat.yml
@@ -0,0 +1,11 @@
+---
+- name: Add application offline package repository
+ yum_repository:
+ name: "{{ item.name }}"
+ file: "{{ item.file }}"
+ description: "{{ item.description | default('') }}"
+ baseurl: "{{ item.baseurl | default('') }}"
+ gpgcheck: "{{ item.gpgcheck | default(true) }}"
+ enabled: "{{ item.enabled | default(false) }}"
+ state: "{{ item.state | default('present') }}"
+ loop: "{{ package_repositories }}"
diff --git a/ansible/roles/package-repository/tasks/main.yml b/ansible/roles/package-repository/tasks/main.yml
index e2a5fd46..763ee659 100644
--- a/ansible/roles/package-repository/tasks/main.yml
+++ b/ansible/roles/package-repository/tasks/main.yml
@@ -23,12 +23,12 @@
insertbefore: BOF
unsafe_writes: true
-- name: Disable all OS default repositories
+- name: Disable all default repositories
block:
- name: Find repo files names
find:
- paths: /etc/yum.repos.d
- pattern: '*.repo'
+ paths: "{{ repo_path[ansible_os_family] }}"
+ pattern: "{{ repo_patern[ansible_os_family] }}"
register: repo_files
- name: Get all defined offline repo names
@@ -49,13 +49,4 @@
loop: "{{ repo_files.files }}"
when: "(item.path | basename | splitext)[0] not in package_repositories_names"
-- name: Add application offline package repository
- yum_repository:
- name: "{{ item.name }}"
- file: "{{ item.file }}"
- description: "{{ item.description | default('') }}"
- baseurl: "{{ item.baseurl | default('') }}"
- gpgcheck: "{{ item.gpgcheck | default(true) }}"
- enabled: "{{ item.enabled | default(false) }}"
- state: "{{ item.state | default('present') }}"
- loop: "{{ package_repositories }}"
+- include_tasks: "{{ ansible_os_family }}.yml"