summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Ptacek <m.ptacek@partner.samsung.com>2019-03-04 08:35:00 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-04 08:35:00 +0000
commit63483034ef17e6be2d4ce0b3b9481b520bd59a01 (patch)
treec93660d322613131ccecadf6113718e798cc2cb7
parent3313c854585836ec97b72e2ff82d9ed4bf4ed710 (diff)
parent6fd567082d827378547d41eb9a83ce41164a4d12 (diff)
Merge "Create setup role"
-rw-r--r--ansible/roles/setup/defaults/main.yml3
-rw-r--r--ansible/roles/setup/tasks/main.yml30
-rw-r--r--ansible/setup.yml28
3 files changed, 37 insertions, 24 deletions
diff --git a/ansible/roles/setup/defaults/main.yml b/ansible/roles/setup/defaults/main.yml
new file mode 100644
index 00000000..e7e89721
--- /dev/null
+++ b/ansible/roles/setup/defaults/main.yml
@@ -0,0 +1,3 @@
+---
+ssh_dir: ~/.ssh
+offline_ssh_key_file_name: offline_ssh_key \ No newline at end of file
diff --git a/ansible/roles/setup/tasks/main.yml b/ansible/roles/setup/tasks/main.yml
new file mode 100644
index 00000000..5ffcbab9
--- /dev/null
+++ b/ansible/roles/setup/tasks/main.yml
@@ -0,0 +1,30 @@
+---
+- name: "Check and generate key if needed"
+ block:
+ - name: ssh dir
+ file:
+ path: "{{ ssh_dir }}"
+ state: directory
+ mode: 0700
+
+ - name: check ssh pub key exists
+ stat:
+ path: '{{ private_key }}.pub'
+ register: p
+
+ - name: generate ssh keys
+ command: ssh-keygen -f {{ private_key }} -t rsa -N ''
+ when: not p.stat.exists
+ vars:
+ private_key: "{{ ssh_dir }}/{{ offline_ssh_key_file_name }}"
+ delegate_to: localhost
+ run_once: true
+
+- name: Setup authorized_keys file
+ authorized_key:
+ user: root
+ state: present
+ key: "{{ lookup('file', public_key) }}"
+ become: true
+ vars:
+ public_key: "{{ ssh_dir }}/{{ offline_ssh_key_file_name }}.pub"
diff --git a/ansible/setup.yml b/ansible/setup.yml
index ec572973..9e4f051d 100644
--- a/ansible/setup.yml
+++ b/ansible/setup.yml
@@ -1,26 +1,6 @@
---
-- hosts: localhost
+- name: Setup nodes for installer
+ hosts: all
gather_facts: false
- tasks:
- - name: "Check and generate key if needed"
- block:
- - stat:
- path: '{{ private_key }}.pub'
- register: p
-
- - command: ssh-keygen -f {{ private_key }} -t rsa -N ''
- when: not p.stat.exists
- vars:
- private_key: /root/.ssh/offline_ssh_key
-
-- hosts: all
- gather_facts: false
- tasks:
- - name: Setup authorized_keys file
- authorized_key:
- user: root
- state: present
- key: "{{ lookup('file', public_key) }}"
- become: true
- vars:
- public_key: /root/.ssh/offline_ssh_key.pub
+ roles:
+ - setup