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