Adding Ubuntu support in Ansible - certificates role 61/101461/6
authorJan Benedikt <j.benedikt@partner.samsung.com>
Mon, 10 Feb 2020 14:15:41 +0000 (15:15 +0100)
committerJan Benedikt <j.benedikt@partner.samsung.com>
Wed, 29 Apr 2020 12:46:09 +0000 (12:46 +0000)
Extending ansible playbooks of ubuntu support.
Creating new test with Ubuntu image for Molecule in certificates role.

Issue-ID: OOM-1671
Signed-off-by: Jan Benedikt <j.benedikt@partner.samsung.com>
Change-Id: I82f0f8590812c277f2969d71f95fb6475c72f7c8

ansible/roles/certificates/defaults/main.yml
ansible/roles/certificates/handlers/main.yml
ansible/roles/certificates/molecule/default/tests/test_default.py
ansible/roles/certificates/molecule/default/tests/test_infrastructure.py
ansible/roles/certificates/molecule/ubuntu/.gitignore [new file with mode: 0644]
ansible/roles/certificates/molecule/ubuntu/group_vars [new symlink]
ansible/roles/certificates/molecule/ubuntu/host_vars [new symlink]
ansible/roles/certificates/molecule/ubuntu/molecule.yml [new file with mode: 0644]
ansible/roles/certificates/tasks/upload_root_ca.yml

index ad3422c..a8bc176 100644 (file)
@@ -2,3 +2,11 @@
 # Generate certs to local current dir where ansible in run (= playbook_dir)
 # After ansible run, dir can be deleted but idempotence is lost and certs are re-generated in next run
 certificates_local_dir: "{{ playbook_dir }}/certs"
+root_ca_path:
+  RedHat: "/etc/pki/ca-trust/source/anchors/"
+  Debian: "/usr/local/share/ca-certificates/"
+extract_root_cert:
+  RedHat:
+    update_command: /usr/bin/update-ca-trust extract
+  Debian:
+    update_command: update-ca-certificates
index 579b522..ed80f53 100644 (file)
@@ -1,5 +1,5 @@
 ---
 - name: Extract root certificate
-  command: /usr/bin/update-ca-trust extract
+  command: "{{ extract_root_cert[ansible_os_family].update_command }}"
   changed_when: true  # this handler is executed just when there is a new cert
   notify: Restart Docker
index d4314e5..16931fb 100644 (file)
@@ -12,8 +12,10 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 ])
 def test_cert_file_installed(host, cert_file):
     os = host.system_info.distribution
-    if os == "centos":
+    if (os == "centos"):
         f = host.file('/etc/pki/ca-trust/source/anchors/' + cert_file)
+    if (os == "ubuntu"):
+        f = host.file('/usr/local/share/ca-certificates/' + cert_file)
 
     assert f.exists
     assert f.user == 'root'
index 56b1293..6a0aec0 100644 (file)
@@ -27,7 +27,13 @@ def test_generated_cert_files_copied_to_infra(host, cert_file, group_vars):
     assert f.user == 'root'
     assert f.group == 'root'
 
+    os = host.system_info.distribution
+    if (os == "centos"):
+        node_directory = "certs/"
+    elif (os == "ubuntu"):
+        node_directory = "../default/certs/"
+
     # Verify cert files content locally is as in node
-    with open("certs/" + cert_file) as local_cert_file:
+    with open(node_directory + cert_file) as local_cert_file:
         local_content = local_cert_file.read().strip()
     assert local_content == f.content_string
diff --git a/ansible/roles/certificates/molecule/ubuntu/.gitignore b/ansible/roles/certificates/molecule/ubuntu/.gitignore
new file mode 100644 (file)
index 0000000..df91287
--- /dev/null
@@ -0,0 +1 @@
+certs/
diff --git a/ansible/roles/certificates/molecule/ubuntu/group_vars b/ansible/roles/certificates/molecule/ubuntu/group_vars
new file mode 120000 (symlink)
index 0000000..5ce8257
--- /dev/null
@@ -0,0 +1 @@
+../default/group_vars/
\ No newline at end of file
diff --git a/ansible/roles/certificates/molecule/ubuntu/host_vars b/ansible/roles/certificates/molecule/ubuntu/host_vars
new file mode 120000 (symlink)
index 0000000..a704613
--- /dev/null
@@ -0,0 +1 @@
+../default/host_vars/
\ No newline at end of file
diff --git a/ansible/roles/certificates/molecule/ubuntu/molecule.yml b/ansible/roles/certificates/molecule/ubuntu/molecule.yml
new file mode 100644 (file)
index 0000000..051379d
--- /dev/null
@@ -0,0 +1,69 @@
+---
+dependency:
+  name: galaxy
+driver:
+  name: docker
+lint:
+  name: yamllint
+platforms:
+  - name: infrastructure-server
+    image: molecule-${PREBUILD_PLATFORM_DISTRO:-ubuntu}:${PREBUILD_DISTRO_VERSION:-18.04}
+    pre_build_image: true
+    privileged: true
+    command: ${MOLECULE_DOCKER_COMMAND:-""}
+    groups:
+      - infrastructure
+  - name: kubernetes-node-1
+    image: molecule-${PREBUILD_PLATFORM_DISTRO:-ubuntu}:${PREBUILD_DISTRO_VERSION:-18.04}
+    pre_build_image: true
+    privileged: true
+    command: ${MOLECULE_DOCKER_COMMAND:-""}
+    groups:
+      - kubernetes
+provisioner:
+  name: ansible
+  log: true
+  lint:
+    name: ansible-lint
+  env:
+    ANSIBLE_ROLES_PATH: ../../../../test/roles
+    ANSIBLE_LIBRARY: ../../../../library
+  playbooks:
+    converge: ../default/playbook.yml
+  inventory:
+    links:
+      group_vars: ../../../../group_vars/
+scenario:
+  name: ubuntu
+  test_sequence:
+    - lint
+    - cleanup
+    - destroy
+    - dependency
+    - syntax
+    - create
+    - prepare
+    - converge
+    # - idempotence
+    #  --> Action: 'idempotence'
+    #  ERROR: Idempotence test failed because of the following tasks:
+    #  * [infrastructure-server -> localhost] => certificates : Generate an OpenSSL CSR.
+    #  * [infrastructure-server -> localhost] => certificates : Generate root CA certificate
+    #  * [infrastructure-server] => certificates : Upload certificates to infrastructure server
+    #  * [infrastructure-server] => certificates : Copy root certificate
+    #  * [infrastructure-server] => certificates : Extract root certificate
+    #  * [infrastructure-server] => docker : Setup docker dns settings
+    #  * [kubernetes-node-1] => certificates : Copy root certificate
+    #  * [kubernetes-node-1] => certificates : Extract root certificate
+    #  * [kubernetes-node-1] => certificates : Extract root certificate
+    - side_effect
+    - verify
+    - cleanup
+    - destroy
+verifier:
+  name: testinfra
+  options:
+    verbose: true
+  lint:
+    name: flake8
+  directory: ../default/tests
index df50b69..d73446b 100644 (file)
@@ -2,6 +2,6 @@
 - name: Copy root certificate
   copy:
     src: "{{ certificates_local_dir }}/rootCA.crt"
-    dest: /etc/pki/ca-trust/source/anchors/
+    dest: "{{ root_ca_path[ansible_os_family] }}"
   notify:  # handler is triggered just when file is changed
     - Extract root certificate