summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYanis Guenane <yguenane@redhat.com>2018-06-19 15:51:07 +0200
committerYanis Guenane <yguenane@redhat.com>2018-06-19 16:16:46 +0200
commite7604d83afaff9c0ce9678bbfe8b99a41cf254c6 (patch)
tree9b2976adbd8cb4d673f26a3d3f0ca8855a400ddd
parent50e19daaa828b865bec2cd2cbcc7c9931a2781e4 (diff)
Refacto of the existing code.
This commit refactores the existing code : * Complete the README.md file * Add the meta/ folder * tasks/main.yml contains only tasks Change-Id: I8043b8e6a87c981a46d5ef0e790a0758ecc5d657
-rw-r--r--README.md25
-rw-r--r--ansible-role-dci-import-keys.spec2
-rw-r--r--meta/main.yml14
-rw-r--r--tasks/main.yml69
4 files changed, 72 insertions, 38 deletions
diff --git a/README.md b/README.md
index acb03e3..cfa532a 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,12 @@
-# ansible-role-dci-feeders
+# ansible-role-dci-import-keys
-An Ansible role that deploys the necessary playbook for a host to act as a DCI feeder
+An Ansible role that automates the process of key retrieval for DCI's RemoteCI.
## Pre-requisites
-This role heavily relies on [python-dciclient](https://github.com/redhat-cip/python-dciclient) and [dci-ansible](https://github.com/redhat-cip/dci-ansible).
+This role relies on [python-dciclient](https://github.com/redhat-cip/python-dciclient) and [dci-ansible](https://github.com/redhat-cip/dci-ansible).
+
If those are not installed, they should be installed before using this role.
@@ -14,10 +15,24 @@ If those are not installed, they should be installed before using this role.
The variables of this role are :
- * `components`: A list of components to check if a new version is available.
+ * `remoteci_id`: ID of the RemoteCI to retrieve the keys for
### Example
```
----
+- hosts: localhost
+ vars:
+ remoteci_id: XXX
+ roles:
+ - dci-import-keys
+```
+
+### License
+
+Apache 2.0
+
+
+### Author Information
+
+Distributed-CI Team <distributed-ci@redhat.com>
diff --git a/ansible-role-dci-import-keys.spec b/ansible-role-dci-import-keys.spec
index e3d003e..a2299ab 100644
--- a/ansible-role-dci-import-keys.spec
+++ b/ansible-role-dci-import-keys.spec
@@ -7,7 +7,7 @@ URL: https://github.com/redhat-cip/ansible-role-dci-import-keys
Source0: ansible-role-dci-import-keys-%{version}.tar.gz
BuildArch: noarch
-Requires: ansible
+Requires: dci-ansible
%description
An Ansible role to automate the key import process
diff --git a/meta/main.yml b/meta/main.yml
new file mode 100644
index 0000000..b0a9f29
--- /dev/null
+++ b/meta/main.yml
@@ -0,0 +1,14 @@
+galaxy_info:
+ author: Distributed-CI Team
+ description: An Ansible role that automates the process of key retrieval for DCI's RemoteCI
+ company: Red Hat
+ license: license (Apache)
+ min_ansible_version: 2.0
+ platforms:
+ - name: EL
+ versions:
+ - 7
+
+ galaxy_tags: []
+
+dependencies: []
diff --git a/tasks/main.yml b/tasks/main.yml
index 4521b18..63a9f6e 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -1,33 +1,38 @@
---
-- name: CHECK KEYS
- hosts: localhost
- become: yes
- become_user: root
- tasks:
- - name: Check ssl dir
- file:
- path: /etc/ssl/repo/
- state: directory
- - name: Check keys
- stat:
- path: /etc/ssl/repo/dci.key
- register: file_key
- - name: Check Cert
- stat:
- path: /etc/ssl/repo/dci.crt
- register: file_cert
- - name: Get keys from DCI
- dci_keys:
- remoteci_id: '{{ remoteci_id }}'
- register: keys
- when: file_key.stat.exists == False or file_cert.stat.exists == False
- - name: Create cert file
- copy:
- content: '{{ keys.cert }}'
- dest: /etc/ssl/repo/dci.crt
- when: keys.cert is defined
- - name: Create key file
- copy:
- content: '{{ keys.key }}'
- dest: /etc/ssl/repo/dci.key
- when: keys.key is defined
+- name: Ensure the SSL directory exist
+ file:
+ path: /etc/ssl/repo/
+ state: directory
+ become: True
+
+- name: Verify if the remoteci key is already installed
+ stat:
+ path: /etc/ssl/repo/dci.key
+ register: file_key
+ become: True
+
+- name: Verify is the remoteci certificate is already installed
+ stat:
+ path: /etc/ssl/repo/dci.crt
+ register: file_cert
+ become: True
+
+- name: Retrieve remoteci key and certificate from DCI
+ dci_keys:
+ remoteci_id: '{{ remoteci_id }}'
+ register: keys
+ when: file_key.stat.exists == False or file_cert.stat.exists == False
+
+- name: Create the certificate file
+ copy:
+ content: '{{ keys.cert }}'
+ dest: /etc/ssl/repo/dci.crt
+ when: keys.cert is defined
+ become: True
+
+- name: Create the private key file
+ copy:
+ content: '{{ keys.key }}'
+ dest: /etc/ssl/repo/dci.key
+ when: keys.key is defined
+ become: True