๐Ÿ“— Ansible playbooks and roles for building an idempotent, interconnected and scalable infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
ansible-playbooks/tasks/query_node.yml

30 lines
921 B

- block:
- name: call pvesh command
command:
cmd: "pvesh get /cluster/resources --type vm --output-format yaml"
register: res
failed_when: no
changed_when: no
delegate_to: "{{ node }}"
no_log: yes
- block:
- name: set temp pvesh result
set_fact:
temp_node_result: "{{ res.stdout | from_yaml | selectattr('vmid', 'equalto', container_id) | list }}"
- name: fail if node is empty or more than one container was found
fail:
when: ((temp_node_result | length) != 1) or (temp_node_result[0].node is not defined)
- name: set selected node
set_fact:
selected_node: "{{ temp_node_result[0].node }}"
- name: set node found result
set_fact:
is_node_found: yes
when: (res.stdout is string) and (res.stdout | length > 0)
when: is_node_found == false