forked from jakub/ansible
Refactor miniplay.yml: remove outdated documentation and improve VM hostname retrieval method for clarity and efficiency.
This commit is contained in:
@@ -1,21 +1,3 @@
|
||||
# """
|
||||
# Run the command and check the response.
|
||||
#
|
||||
# :parameter command: The command to be executed.
|
||||
# :parameter add_command: Whether to include the command in the database values.
|
||||
# :parameter add_response: Whether to include the response in the database values.
|
||||
# :parameter measurement: The measurement index for the command.
|
||||
# :parameter measure_retries: The number of retries for measurement in case of failure.
|
||||
# :parameter check_port: Whether to check the port before sending the command.
|
||||
# :parameter response_equals: The expected response string to compare against.
|
||||
# :parameter response_length: The expected length or format of the response.
|
||||
# :parameter send_skipped: Whether to mark the test as skipped without execution.
|
||||
# :parameter no_response: Whether to expect no response from the command.
|
||||
# :parameter expect_patch_id_decimal: The expected patch ID in decimal format for validation.
|
||||
# :parameter response_equals_match: The expected response string to match against.
|
||||
# :return: RunResultType
|
||||
# """
|
||||
|
||||
- name: Get VM hostname via Proxmox jump
|
||||
hosts: proxmox
|
||||
gather_facts: false
|
||||
@@ -29,21 +11,29 @@
|
||||
vm_pass: "Papadopolus0"
|
||||
|
||||
tasks:
|
||||
- name: Ensure sshpass is installed (for password-based SSH)
|
||||
- name: Ensure sshpass is installed (for password-based SSH) # English comments as requested
|
||||
ansible.builtin.apt:
|
||||
name: sshpass
|
||||
state: present
|
||||
update_cache: yes
|
||||
|
||||
- name: Get hostname from VM
|
||||
ansible.builtin.command: >
|
||||
bash -lc "sshpass -p '{{ vm_pass }}'
|
||||
ssh -o StrictHostKeyChecking=no
|
||||
-o ConnectTimeout=10
|
||||
{{ vm_user }}@{{ vm_ip }} hostname"
|
||||
- name: Get hostname from VM using argv (no shell, no line breaks)
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- sshpass
|
||||
- -p
|
||||
- "{{ vm_pass }}"
|
||||
- ssh
|
||||
- -o
|
||||
- StrictHostKeyChecking=no
|
||||
- -o
|
||||
- ConnectTimeout=10
|
||||
- "{{ vm_user }}@{{ vm_ip }}"
|
||||
- hostname
|
||||
register: vm_hostname
|
||||
changed_when: false
|
||||
failed_when: vm_hostname.rc != 0
|
||||
no_log: false # set to true once you move creds into Vault
|
||||
|
||||
- name: Print VM hostname
|
||||
ansible.builtin.debug:
|
||||
|
||||
Reference in New Issue
Block a user