---
- name: 'Create Hostgroups'  # noqa: args[module]
  theforeman.foreman.hostgroup:
    username: "{{ foreman_username | default(omit) }}"
    password: "{{ foreman_password | default(omit) }}"
    server_url: "{{ foreman_server_url | default(omit) }}"
    validate_certs: "{{ foreman_validate_certs | default(omit) }}"
    name: "{{ item.name }}"
    updated_name: "{{ item.updated_name | default(omit) }}"
    description: "{{ item.description | default(omit) }}"
    parent: "{{ item.parent | default(omit) }}"
    organization: "{{ item.organization | default(omit) }}"
    organizations: "{{ item.organizations | default(omit) }}"
    locations: "{{ item.locations | default(omit) }}"
    architecture: "{{ item.architecture | default(omit) }}"
    operatingsystem: "{{ item.operatingsystem | default(omit) }}"
    medium: "{{ item.medium | default(omit) }}"
    ptable: "{{ item.ptable | default(omit) }}"
    parameters: "{{ item.parameters | default(omit) }}"
    ansible_roles: "{{ item.ansible_roles | default(omit) }}"
    compute_resource: "{{ item.compute_resource | default(omit) }}"
    compute_profile: "{{ item.compute_profile | default(omit) }}"
    domain: "{{ item.domain | default(omit) }}"
    subnet: "{{ item.subnet | default(omit) }}"
    subnet6: "{{ item.subnet6 | default(omit) }}"
    root_pass: "{{ item.root_pass | default(omit) }}"
    realm: "{{ item.realm | default(omit) }}"
    pxe_loader: "{{ item.pxe_loader | default(omit) }}"
    environment: "{{ item.environment | default(omit) }}"
    puppetclasses: "{{ item.puppetclasses | default(omit) }}"
    config_groups: "{{ item.config_groups | default(omit) }}"
    puppet_proxy: "{{ item.puppet_proxy | default(omit) }}"
    puppet_ca_proxy: "{{ item.puppet_ca_proxy | default(omit) }}"
    openscap_proxy: "{{ item.openscap_proxy | default(omit) }}"
    content_source: "{{ item.content_source | default(omit) }}"
    lifecycle_environment: "{{ item.lifecycle_environment | default(omit) }}"
    kickstart_repository: "{{ item.kickstart_repository | default(omit) }}"
    content_view: "{{ item.content_view | default(omit) }}"
    activation_keys: "{{ item.activation_keys | default(omit) }}"
    state: "{{ item.state | default(omit) }}"
  no_log: "{{ item.root_pass is defined }}"
  with_items:
    - "{{ foreman_hostgroups }}"
