ansible_lxd_tests/Playbooks/roles/lxc_configue_ssh/tasks/main.yml

48 lines
1.2 KiB
YAML

---
# profile: default
# lxc
# ssh_user: renzo
# ssh_key_path: ~/.ssh/lxd_ssh
# ssh_key_name: lxd_ssh
# ssh_key_passphrase: set_a_password!
# tasks file for roles/init_lxd
- name: generate SSH key "{{ssh_key_name}}"
register: SSH_KEY
user:
name: "{{ssh_user}}"
generate_ssh_key: yes
ssh_key_type: rsa
ssh_key_bits: 4096
ssh_key_file: "{{ssh_key_path}}"
ssh_key_passphrase: "{{ssh_passphrase}}"
force: no
# Default profile
- shell: "lxc profile show {{profile}}"
become: true
register: profile
# Process of custom profile with my new SSH Key
- set_fact:
lookup_custom_conf: |
config:
user.user-data: |
ssh_authorized_keys:
- {{SSH_KEY.ssh_public_key}}
# Apply merge in LXD
- ansible.builtin.tempfile: {}
register: temp_lxd_config
- set_fact: custom_config="{{ lookup_custom_conf | from_yaml }}"
- set_fact: profile_yaml_path="{{temp_lxd_config.path}}"
- copy:
dest: "{{profile_yaml_path}}"
content: |
{{ profile.stdout | from_yaml | combine(custom_config) | to_yaml }}
- shell: "lxc profile edit {{profile}} < {{profile_yaml_path}}"
become: true
- file: path="{{profile_yaml_path}}" state=absent