summaryrefslogtreecommitdiffstats
path: root/xci/playbooks/manage-ssh-keys.yml
blob: ff797aad3ff86599ace2189b0aae9ef6c6c3db3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2018 SUSE Linux GmbH and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
- name: Configure SSH key for root user
  user:
    name: root
    generate_ssh_key: yes
    ssh_key_bits: 2048
    ssh_key_comment: xci
    ssh_key_type: rsa
    state: present

- name: Determine local user
  become: no
  local_action: command whoami
  changed_when: False
  register: _ansible_user

- name: Fetch local SSH key
  delegate_to: localhost
  become: no
  slurp:
    src: "/home/{{ _ansible_user.stdout }}/.ssh/id_rsa.pub"
  register: _local_ssh_key

- name: Fetch OPNFV SSH key
  delegate_to: opnfv
  slurp:
    src: "{{ ansible_env.HOME }}/.ssh/id_rsa.pub"
  register: _opnfv_ssh_key

- name: "Configure {{ inventory_hostname }} authorized_keys file"
  authorized_key:
    exclusive: "{{ item.exclusive }}"
    user: root
    state: present
    manage_dir: yes
    key: "{{ item.key }}"
    comment: "{{ item.comment }}"
  with_items:
    - { key: "{{ _local_ssh_key['content'] | b64decode }}", comment: "{{ _ansible_user.stdout }} key", exclusive: yes }
    - { key: "{{ _opnfv_ssh_key['content'] | b64decode }}", comment: "opnfv host key", exclusive: no }