ansible-lint fixes to kvm guest deployment

This commit is contained in:
Timo Makinen 2022-10-31 18:07:48 +00:00
parent 2e97e2af9e
commit d3c08cf674

View file

@ -41,22 +41,22 @@
tasks: tasks:
- name: get vm list - name: Get VM list
virt: community.libvirt.virt:
command: list_vms command: list_vms
delegate_to: "{{ vmhost }}" delegate_to: "{{ vmhost }}"
register: result register: result
check_mode: false check_mode: false
- name: clean up old facts cache - name: Clean up old facts cache
file: ansible.builtin.file:
path: "{{ ansible_dir_root }}/facts/{{ inventory_hostname }}" path: "{{ ansible_dir_root }}/facts/{{ inventory_hostname }}"
state: absent state: absent
delegate_to: localhost delegate_to: localhost
when: inventory_hostname not in result.list_vms when: inventory_hostname not in result.list_vms
- name: create temp directory - name: Create temp directory
tempfile: ansible.builtin.tempfile:
state: directory state: directory
register: tmpdir register: tmpdir
delegate_to: "{{ vmhost }}" delegate_to: "{{ vmhost }}"
@ -64,8 +64,8 @@
- inventory_hostname not in result.list_vms - inventory_hostname not in result.list_vms
- inject is defined - inject is defined
- name: create inject file - name: Create inject file
copy: ansible.builtin.copy:
content: | content: |
rootpw --lock rootpw --lock
%post %post
@ -79,8 +79,8 @@
- inventory_hostname not in result.list_vms - inventory_hostname not in result.list_vms
- inject is defined - inject is defined
- name: run virt-install - name: Run virt-install
command: > ansible.builtin.command: >
virt-install --name {{ inventory_hostname }} \ virt-install --name {{ inventory_hostname }} \
--graphics none --boot useserial=on --noautoconsole \ --graphics none --boot useserial=on --noautoconsole \
--serial pty,log.file={{ console_log }} --sound none \ --serial pty,log.file={{ console_log }} --sound none \
@ -106,8 +106,8 @@
delegate_to: "{{ vmhost }}" delegate_to: "{{ vmhost }}"
when: inventory_hostname not in result.list_vms when: inventory_hostname not in result.list_vms
- name: wait for install to finish - name: Wait for install to finish
virt: community.libvirt.virt:
name: "{{ inventory_hostname }}" name: "{{ inventory_hostname }}"
command: status command: status
register: vmstatus register: vmstatus
@ -117,22 +117,22 @@
delegate_to: "{{ vmhost }}" delegate_to: "{{ vmhost }}"
when: inventory_hostname not in result.list_vms when: inventory_hostname not in result.list_vms
- name: clean tempdir - name: Clean tempdir
file: ansible.builtin.file:
path: "{{ tmpdir.path }}" path: "{{ tmpdir.path }}"
state: absent state: absent
delegate_to: "{{ vmhost }}" delegate_to: "{{ vmhost }}"
when: tmpdir.path is defined when: tmpdir.path is defined
- name: start vm - name: Start VM
virt: community.libvirt.virt:
name: "{{ inventory_hostname }}" name: "{{ inventory_hostname }}"
command: start command: start
delegate_to: "{{ vmhost }}" delegate_to: "{{ vmhost }}"
when: inventory_hostname not in result.list_vms when: inventory_hostname not in result.list_vms
- name: wait for ssh to start - name: Wait for ssh to start
wait_for: ansible.builtin.wait_for:
delay: 10 delay: 10
host: "{{ inventory_hostname }}" host: "{{ inventory_hostname }}"
port: 22 port: 22
@ -141,13 +141,19 @@
delegate_to: localhost delegate_to: localhost
when: inventory_hostname not in result.list_vms when: inventory_hostname not in result.list_vms
- name: get ssh keys from new host - name: Get SSH public keys from new host
local_action: command ssh-keyscan -t ed25519 {{ inventory_hostname }} ansible.builtin.command:
argv:
- ssh-keyscan
- -t
- ed25519
- "{{ inventory_hostname }}"
delegate_to: localhost
register: hostkeys register: hostkeys
when: inventory_hostname not in result.list_vms when: inventory_hostname not in result.list_vms
- name: add new ssh host key to known_hosts - name: Add new SSH host key to known_hosts
known_hosts: ansible.builtin.known_hosts:
path: /root/.ssh/known_hosts path: /root/.ssh/known_hosts
key: "{{ item }}" key: "{{ item }}"
host: "{{ inventory_hostname }}" host: "{{ inventory_hostname }}"
@ -155,8 +161,12 @@
delegate_to: localhost delegate_to: localhost
when: inventory_hostname not in result.list_vms when: inventory_hostname not in result.list_vms
- name: install python if required - name: Install python if required
command: "ssh {{ inventory_hostname }} '{{ virt_install_python_cmd }}'" ansible.builtin.command:
argv:
- ssh
- "{{ inventory_hostname }}"
- "{{ virt_install_python_cmd }}"
delegate_to: localhost delegate_to: localhost
when: when:
- inventory_hostname not in result.list_vms - inventory_hostname not in result.list_vms