+---
+# ============LICENSE_START=======================================================
+# Copyright (C) 2021 The Nordix Foundation. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=========================================================
+
+- name: Check if '{{ admin_user }}' exists on target nodes
+ command: id -a {{ admin_user }}
+ changed_when: false
+ register: user_check
+ ignore_errors: true
+
+- name: Create '{{ admin_user }}' on target nodes
+ user:
+ name: "{{ admin_user }}"
+ groups: sudo
+ append: true
+ shell: /bin/bash
+ when: user_check.rc == 1
+
+- name: Create directory '{{ admin_user_ssh_dir }}' on target nodes
+ file:
+ path: "{{ admin_user_ssh_dir }}"
+ state: directory
+ owner: "{{ admin_user }}"
+ group: "{{ admin_user }}"
+ mode: 0700
+
+- name: Append ssh public key to authorized_keys on target nodes
+ lineinfile:
+ path: "{{ admin_user_ssh_dir }}/authorized_keys"
+ line: "{{ lookup('file', '{{ nolabs_user_public_key }}') }}"
+ create: true
+ state: present
+ owner: "{{ admin_user }}"
+ group: "{{ admin_user }}"
+ mode: 0600
+
+- name: Create SSH keypair for '{{ admin_user }}'
+ openssh_keypair:
+ path: "{{ admin_user_private_key }}"
+ type: rsa
+ size: 4096
+ state: present
+ owner: "{{ admin_user }}"
+ group: "{{ admin_user }}"
+ mode: 0600
+
+- name: Fetch '{{ admin_user }}' SSH public key
+ fetch:
+ src: "{{ admin_user_public_key }}"
+ dest: "{{ admin_user_jumphost_public_key }}"
+ flat: true
+ remote_src: true
+ force: true
+
+- name: Enable passwordless sudo on target nodes
+ lineinfile:
+ path: /etc/sudoers
+ line: "{{ admin_user }} ALL=(ALL:ALL) NOPASSWD: ALL"
+
+- name: Remove nordix ssh keys
+ file:
+ path: /root/.ssh/{{ item }}
+ state: absent
+ with_items:
+ - id_rsa
+ - id_rsa.pub
+ - authorized_keys
+
+# vim: set ts=2 sw=2 expandtab:
\ No newline at end of file