Playbook #1

/root/kubeinit/ci/builds/6mbKNrxD/0/kubeinit/kubeinit/kubeinit-aux/kubeinit/playbook.yml

Report Status CLI Date Duration Controller User Versions Hosts Plays Tasks Results Files Records
31 Oct 2023 01:55:37 +0000 00:14:45.01 nyctea root Ansible 2.15.2 ara 1.6.1 (client), 1.6.1 (server) Python 3.11.4 5 9 708 708 43 1

File: /root/.ansible/collections/ansible_collections/kubeinit/kubeinit/roles/kubeinit_libvirt/tasks/60_create_cloud_user.yml

---
# Copyright kubeinit contributors
# 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.

- name: "Make sure we have a group called {{ kubeinit_libvirt_cloud_user }}"
  ansible.builtin.group:
    name: "{{ kubeinit_libvirt_cloud_user }}"
    state: present

- name: "Allow to have passwordless sudo to the group {{ kubeinit_libvirt_cloud_user }}"
  ansible.builtin.lineinfile:
    dest: /etc/sudoers
    state: present
    regexp: "^%{{ kubeinit_libvirt_cloud_user }}"
    line: "%{{ kubeinit_libvirt_cloud_user }} ALL=(ALL) NOPASSWD: ALL"
    validate: 'visudo -cf %s'
    mode: '0644'

- name: "Add sudoers users to the group {{ kubeinit_libvirt_cloud_user }}"
  ansible.builtin.user:
    name: "{{ kubeinit_libvirt_cloud_user }}"
    groups: "{{ kubeinit_libvirt_cloud_user }}"
    append: yes
    state: present
    createhome: yes

- name: Add cloud user to libvirt
  ansible.builtin.user:
    name: "{{ kubeinit_libvirt_cloud_user }}"
    groups: "kvm,libvirt"
    append: yes

- name: Create ssh folder
  ansible.builtin.file:
    path: "/home/{{ kubeinit_libvirt_cloud_user }}/.ssh/"
    owner: "{{ kubeinit_libvirt_cloud_user }}"
    group: "{{ kubeinit_libvirt_cloud_user }}"
    state: directory
    mode: '0700'

- name: Generate an OpenSSH keypair
  community.crypto.openssh_keypair:
    path: "/home/{{ kubeinit_libvirt_cloud_user }}/.ssh/id_{{ kubeinit_ssh_keytype }}"
    type: "{{ kubeinit_ssh_keytype }}"
    comment: "{{ kubeinit_cluster_name }} {{ kubeinit_libvirt_cloud_user }}"
    owner: "{{ kubeinit_libvirt_cloud_user }}"
    group: "{{ kubeinit_libvirt_cloud_user }}"
    regenerate: 'never'

- name: Fix owner of the generated pub key
  ansible.builtin.file:
    path: "/home/{{ kubeinit_libvirt_cloud_user }}/.ssh/id_{{ kubeinit_ssh_keytype }}.pub"
    owner: "{{ kubeinit_libvirt_cloud_user }}"
    group: "{{ kubeinit_libvirt_cloud_user }}"
    mode: '0644'

- name: Insert the default libvirt uri in user's home
  ansible.builtin.lineinfile:
    path: "/home/{{ kubeinit_libvirt_cloud_user }}/.bashrc"
    line: export LIBVIRT_DEFAULT_URI=qemu:///system
    mode: '0644'