From bc1cb936832f6cdcc44b6f9331294740f020dc99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ne=C4=8Das?= Date: Thu, 13 Oct 2022 09:23:14 +0200 Subject: [PATCH 1/2] CI: Add ignore of fqcn for internal plugins (#602) --- .config/ansible-lint.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.config/ansible-lint.yml b/.config/ansible-lint.yml index 2270d995..77bdaa93 100644 --- a/.config/ansible-lint.yml +++ b/.config/ansible-lint.yml @@ -11,3 +11,7 @@ warn_list: - fqcn-builtins - template-instead-of-copy - jinja[invalid] + - fqcn[action-core] + - fqcn[action] + - name[missing] + - deprecated-module From 11a9b4f8ebe762d39df334213b73633cbbd6fcd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ne=C4=8Das?= Date: Thu, 13 Oct 2022 09:45:49 +0200 Subject: [PATCH 2/2] [WIP] Filters: Add docs (#603) * Filters: Add docs * Add changelog --- changelogs/fragments/603-add-filter-docs.yml | 3 ++ plugins/filter/convert_to_bytes.yml | 22 ++++++++++++ plugins/filter/filtervalue.yml | 30 ++++++++++++++++ plugins/filter/get_network_xml_to_dict.yml | 22 ++++++++++++ plugins/filter/get_ovf_disk_size.yml | 25 +++++++++++++ plugins/filter/json_query.yml | 20 +++++++++++ plugins/filter/ovirtdiff.yml | 35 +++++++++++++++++++ plugins/filter/ovirtvmip.yml | 31 ++++++++++++++++ plugins/filter/ovirtvmips.yml | 31 ++++++++++++++++ plugins/filter/ovirtvmipsv4.yml | 31 ++++++++++++++++ plugins/filter/ovirtvmipsv6.yml | 31 ++++++++++++++++ plugins/filter/ovirtvmipv4.yml | 31 ++++++++++++++++ plugins/filter/ovirtvmipv6.yml | 31 ++++++++++++++++ plugins/filter/removesensitivevmdata.yml | 22 ++++++++++++ ...lter_libvirt_default_net_configuration.yml | 2 +- 15 files changed, 366 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/603-add-filter-docs.yml create mode 100644 plugins/filter/convert_to_bytes.yml create mode 100644 plugins/filter/filtervalue.yml create mode 100644 plugins/filter/get_network_xml_to_dict.yml create mode 100644 plugins/filter/get_ovf_disk_size.yml create mode 100644 plugins/filter/json_query.yml create mode 100644 plugins/filter/ovirtdiff.yml create mode 100644 plugins/filter/ovirtvmip.yml create mode 100644 plugins/filter/ovirtvmips.yml create mode 100644 plugins/filter/ovirtvmipsv4.yml create mode 100644 plugins/filter/ovirtvmipsv6.yml create mode 100644 plugins/filter/ovirtvmipv4.yml create mode 100644 plugins/filter/ovirtvmipv6.yml create mode 100644 plugins/filter/removesensitivevmdata.yml diff --git a/changelogs/fragments/603-add-filter-docs.yml b/changelogs/fragments/603-add-filter-docs.yml new file mode 100644 index 00000000..48f5a4eb --- /dev/null +++ b/changelogs/fragments/603-add-filter-docs.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - filters - Add documentation to all filters (https://github.com/oVirt/ovirt-ansible-collection/pull/603). diff --git a/plugins/filter/convert_to_bytes.yml b/plugins/filter/convert_to_bytes.yml new file mode 100644 index 00000000..7f089352 --- /dev/null +++ b/plugins/filter/convert_to_bytes.yml @@ -0,0 +1,22 @@ +DOCUMENTATION: + name: convert_to_bytes + author: Martin Necas (@mnecas) + # version_added: 'historical' + short_description: Convert units to bytes + description: + - This method convert units to bytes, which follow IEC standard + positional: _input + options: + _input: + description: Value to be converted + type: string + required: true + +EXAMPLES: | + - name: Get number of bytes + ansible.builtin.set_fact: + disk_size: "{{ '1KiB' | @NAMESPACE@.@NAME@.convert_to_bytes }}" +RETURN: + _value: + description: Amount of bytes + type: int diff --git a/plugins/filter/filtervalue.yml b/plugins/filter/filtervalue.yml new file mode 100644 index 00000000..f47466a0 --- /dev/null +++ b/plugins/filter/filtervalue.yml @@ -0,0 +1,30 @@ +DOCUMENTATION: + name: filtervalue + author: Martin Necas (@mnecas) + short_description: Filter to findall occurance of some value in dict + description: + - Filter to findall occurance of some value in dict + positional: _input, attr, value + options: + _input: + description: List of VMs + type: list + required: true + attr: + description: Attribute to sotr by + type: list + required: true + value: + description: List of VMs + type: list + required: true + +EXAMPLES: | + - name: Set filtred ovirt_vms + ansible.builtin.set_fact: + ovirt_vms: "{{ vms | @NAMESPACE@.@NAME@.filtervalue('name', item.name) }}" + +RETURN: + _value: + description: Filtred VMs + type: list diff --git a/plugins/filter/get_network_xml_to_dict.yml b/plugins/filter/get_network_xml_to_dict.yml new file mode 100644 index 00000000..78d62691 --- /dev/null +++ b/plugins/filter/get_network_xml_to_dict.yml @@ -0,0 +1,22 @@ +DOCUMENTATION: + name: get_network_xml_to_dict + author: Martin Necas (@mnecas) + short_description: Get network bridge and uuid to dict + description: + - Get network bridge and uuid to dict + positional: _input + options: + _input: + description: xml + type: string + required: true + +EXAMPLES: | + - name: Set network_dict from default_net_xml + ansible.builtin.set_fact: + network_dict: "{{ default_net_xml['stdout'] | @NAMESPACE@.@NAME@.get_network_xml_to_dict }}" + +RETURN: + _value: + description: Dict of network + type: dict diff --git a/plugins/filter/get_ovf_disk_size.yml b/plugins/filter/get_ovf_disk_size.yml new file mode 100644 index 00000000..ece45029 --- /dev/null +++ b/plugins/filter/get_ovf_disk_size.yml @@ -0,0 +1,25 @@ +DOCUMENTATION: + name: get_ovf_disk_size + author: Asaf Rachmani (@arachmani) + # version_added: 'historical' + short_description: Get OVF disk size + description: + - Get OVF disk size. + positional: _input + options: + _input: + description: OVF data + type: string + required: true + +EXAMPLES: | + - name: Get ovf data + ansible.builtin.command: cat "{{ path }}" + register: ovf_data + - name: Get disk size from ovf data + ansible.builtin.set_fact: + disk_size: "{{ ovf_data['stdout'] | @NAMESPACE@.@NAME@.get_ovf_disk_size }}" +RETURN: + _value: + description: OVF disk size + type: string diff --git a/plugins/filter/json_query.yml b/plugins/filter/json_query.yml new file mode 100644 index 00000000..91d94281 --- /dev/null +++ b/plugins/filter/json_query.yml @@ -0,0 +1,20 @@ +DOCUMENTATION: + name: json_query + short_description: Copy of community.general.json_query + description: + - Copy of community.general.json_query used internally in the collection to ease RPM packaging, so we don't need to package/release/support the whole community.general collection for RHV customers + - The original can be found at link https://github.com/ansible-collections/community.general/blob/main/plugins/filter/json_query.py + positional: _input + options: + _input: + description: Value to be converted + type: string + required: true + +EXAMPLES: | + Query data using jmespath query language ( http://jmespath.org ). Example: + - ansible.builtin.debug: msg="{{ instance | json_query(tagged_instances[*].block_device_mapping.*.volume_id') }}" +RETURN: + _value: + description: query + type: string diff --git a/plugins/filter/ovirtdiff.yml b/plugins/filter/ovirtdiff.yml new file mode 100644 index 00000000..31a75ac0 --- /dev/null +++ b/plugins/filter/ovirtdiff.yml @@ -0,0 +1,35 @@ +DOCUMENTATION: + name: ovirtdiff + author: Martin Necas (@mnecas) + short_description: Show what will be changed in next run of the VM + description: + - Show what will be changed in next run of the VM + positional: _input + options: + _input: + description: VM + type: dict + required: true + +EXAMPLES: | + - name: Get VM myvm + ovirt_vm_info: + auth: "{{ ovirt_auth }}" + pattern: 'name={{ myvm }}' + next_run: false + register: vm + + - name: Get next_run of VM myvm + ovirt_vm_info: + auth: "{{ ovirt_auth }}" + pattern: 'name={{ myvm }}' + next_run: true + register: vm_next_run + + - name: Print what will be changed in next run of the VM + debug: + msg: "{{ vm.ovirt_vms[0] | @NAMESPACE@.@NAME@.ovirtdiff(vm_next_run.ovirt_vms[0]) }}" +RETURN: + _value: + description: VM + type: dict diff --git a/plugins/filter/ovirtvmip.yml b/plugins/filter/ovirtvmip.yml new file mode 100644 index 00000000..50c86d15 --- /dev/null +++ b/plugins/filter/ovirtvmip.yml @@ -0,0 +1,31 @@ +DOCUMENTATION: + name: ovirtvmip + author: Martin Necas (@mnecas) + short_description: Return first IP + description: + - Return first IP + positional: _input, attr, network_ip + options: + _input: + description: List of VMs + type: list + required: true + attr: + description: Attribute by which the + type: list + network_ip: + description: Filter the IPs by network address + type: string + +EXAMPLES: | + - name: Print VM IP + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmip }}" + - name: Print VM IP + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmip(attr='name') }}" + +RETURN: + _value: + description: First IP + type: list diff --git a/plugins/filter/ovirtvmips.yml b/plugins/filter/ovirtvmips.yml new file mode 100644 index 00000000..6f56f20c --- /dev/null +++ b/plugins/filter/ovirtvmips.yml @@ -0,0 +1,31 @@ +DOCUMENTATION: + name: ovirtvmips + author: Martin Necas (@mnecas) + short_description: VM all IPs + description: + - VM all IPs + positional: _input + options: + _input: + description: List of VMs + type: list + required: true + attr: + description: Attribute by which the + type: list + network_ip: + description: Filter the IPs by network address + type: string + +EXAMPLES: | + - name: Print VM all IPs + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmips }}" + - name: Print VM all IPs + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmips(attr='name') }}" + +RETURN: + _value: + description: All IPs + type: list diff --git a/plugins/filter/ovirtvmipsv4.yml b/plugins/filter/ovirtvmipsv4.yml new file mode 100644 index 00000000..265b54de --- /dev/null +++ b/plugins/filter/ovirtvmipsv4.yml @@ -0,0 +1,31 @@ +DOCUMENTATION: + name: ovirtvmipsv4 + author: Martin Necas (@mnecas) + short_description: VM IPv4 + description: + - VM IPv4 + positional: _input + options: + _input: + description: List of VMs + type: list + required: true + attr: + description: Attribute by which the + type: list + network_ip: + description: Filter the IPs by network address + type: string + +EXAMPLES: | + - name: Print VM all IPv4 + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmipsv4 }}" + - name: Print VM all IPv4 + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmipsv4(attr='name') }}" + +RETURN: + _value: + description: VM IPv4 + type: list diff --git a/plugins/filter/ovirtvmipsv6.yml b/plugins/filter/ovirtvmipsv6.yml new file mode 100644 index 00000000..5a1cb7ad --- /dev/null +++ b/plugins/filter/ovirtvmipsv6.yml @@ -0,0 +1,31 @@ +DOCUMENTATION: + name: ovirtvmipsv6 + author: Martin Necas (@mnecas) + short_description: VM IPv4 + description: + - VM IPv4 + positional: _input + options: + _input: + description: List of VMs + type: list + required: true + attr: + description: Attribute by which the + type: list + network_ip: + description: Filter the IPs by network address + type: string + +EXAMPLES: | + - name: Print VM all IPv6 + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmipsv6 }}" + - name: Print VM all IPv6 + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmipsv6(attr='name') }}" + +RETURN: + _value: + description: VM IPv4 + type: list diff --git a/plugins/filter/ovirtvmipv4.yml b/plugins/filter/ovirtvmipv4.yml new file mode 100644 index 00000000..51883c75 --- /dev/null +++ b/plugins/filter/ovirtvmipv4.yml @@ -0,0 +1,31 @@ +DOCUMENTATION: + name: ovirtvmipv4 + author: Martin Necas (@mnecas) + short_description: VM IPv4 + description: + - VM IPv4 + positional: _input + options: + _input: + description: List of VMs + type: list + required: true + attr: + description: Attribute by which the + type: list + network_ip: + description: Filter the IPs by network address + type: string + +EXAMPLES: | + - name: Print VM IPv4 + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmipv4 }}" + - name: Print VM IPv4 + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmipv4(attr='name') }}" + +RETURN: + _value: + description: VM IPv4 + type: list diff --git a/plugins/filter/ovirtvmipv6.yml b/plugins/filter/ovirtvmipv6.yml new file mode 100644 index 00000000..0f639de9 --- /dev/null +++ b/plugins/filter/ovirtvmipv6.yml @@ -0,0 +1,31 @@ +DOCUMENTATION: + name: ovirtvmipv6 + author: Martin Necas (@mnecas) + short_description: VM IPv4 + description: + - VM IPv4 + positional: _input + options: + _input: + description: List of VMs + type: list + required: true + attr: + description: Attribute by which the + type: list + network_ip: + description: Filter the IPs by network address + type: string + +EXAMPLES: | + - name: Print VM IPv6 + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmipv6 }}" + - name: Print VM IPv6 + debug: + msg: "{{ vms.ovirt_vms | @NAMESPACE@.@NAME@.ovirtvmipv6(attr='name') }}" + +RETURN: + _value: + description: VM IPv4 + type: list diff --git a/plugins/filter/removesensitivevmdata.yml b/plugins/filter/removesensitivevmdata.yml new file mode 100644 index 00000000..5c79695f --- /dev/null +++ b/plugins/filter/removesensitivevmdata.yml @@ -0,0 +1,22 @@ +DOCUMENTATION: + name: removesensitivevmdata + author: Martin Necas (@mnecas) + short_description: removesensitivevmdata internal filter + description: + - removesensitivevmdata internal filter + positional: _input + options: + _input: + description: List of VMs + type: list + required: true + +EXAMPLES: | + - name: Print VM + debug: + msg: "{{ vms | @NAMESPACE@.@NAME@.removesensitivevmdata }}" + +RETURN: + _value: + description: List of VMs + type: list diff --git a/roles/hosted_engine_setup/tasks/alter_libvirt_default_net_configuration.yml b/roles/hosted_engine_setup/tasks/alter_libvirt_default_net_configuration.yml index bcc5913e..0539d89b 100644 --- a/roles/hosted_engine_setup/tasks/alter_libvirt_default_net_configuration.yml +++ b/roles/hosted_engine_setup/tasks/alter_libvirt_default_net_configuration.yml @@ -6,7 +6,7 @@ - name: Set network_dict from default_net_xml ansible.builtin.set_fact: - network_dict: "{{ default_net_xml['stdout'] | ovirt.ovirt.get_network_xml_to_dict }}" + network_dict: "{{ default_net_xml['stdout'] | @NAMESPACE@.@NAME@.get_network_xml_to_dict }}" - name: Create he-network-config.xml from network-config.j2 template ansible.builtin.template: