Using foreman-ansible-modules to create a managed host not working

Problem:

I’m trying to use foreman-ansible-modules to populate foreman with hosts from an ansible inventory, however when using the foreman_host ansible module it requires several attributes that are missing but I can’t see how to add them.

Using the following task as an example:

    - name: "Create host"
      theforeman.foreman.foreman_host:
        hostgroup: "Test_hostgroup"
        location: "Default Location"
        name: "Test_name"
        organization: "Default Organization"
        password: PASSWORD
        server_url: SERVER_ADDRESS
        state: present
        username: USERNAME

When I run the play, I get the following errors:

"errors": {
    "architecture_id": [
      "can't be blank"
    ],
    "interfaces.ip": [
      "can't be blank"
    ],
    "interfaces.ip6": [
      "can't be blank"
    ],
    "interfaces.mac": [
      "can't be blank"
    ],
    "operatingsystem_id": [
      "can't be blank"
    ]
  },
  "full_messages": [
    "Mac can't be blank",
    "Ip can't be blank",
    "Ip6 can't be blank",
    "Operatingsystem can't be blank",
    "Architecture can't be blank"
  ]

However, taking interfaces for example, there’s no mention of how to add interfaces within the foreman_host module - foreman_host – Manage Foreman hosts — Foreman Ansible Modules documentation

I’ve tried adding an interfaces list to the host like this:

    - name: "Create host"
      theforeman.foreman.foreman_host:
        hostgroup: "Test_hostgroup"
        interfaces:
          - ip: IP_HERE
            mac: MAC_HERE
            subnet: SUBNET_HERE
        location: "Default Location"
        name: "Test_name"
        organization: "Default Organization"
        password: PASSWORD
        server_url: SERVER_ADDRESS
        state: present
        username: USERNAME

But it then complains about unsupported parameters:

"Unsupported parameters for (theforeman.foreman.foreman_host) module: interfaces Supported parameters include: build, enabled, hostgroup, location, managed, name, organization, password, server_url, state, username, validate_certs"

How is this intended to work?

Any advice about an alternative method of populating foreman with a vast list of hosts/subnets/domains would also be welcomed if there is an easier/recommended method of doing this

Foreman and Proxy versions:

1.24.2

Just discovered this…

I was able actually get passed that error.

The reason is because you are not delegating to localhost.

  • name: “Create a host”
    theforeman.foreman.host:
    username: user
    password: password
    server_url: “{{ server_url }}”
    name: testnick2.home.test
    hostgroup: Base Sever/Centos 7.8.2003
    managed: true
    build: yes
    compute_profile: “{{ compute_profile }}”
    compute_resource: “{{ computer_resource }}”
    compute_attributes:
    cpus: 2
    memory_mb: 4096
    interfaces_attributes:

    • type: “interface”
      primary: true
      compute_attributes:
      name: nic1
      network: home
      interface: “VMXNET3”
      subnet: 192.168.10.1
      ip: 192.168.10.12
      domain: “{{ domain }}”
      provision: yes
      operatingsystem: Centos 7.8.2003
      architecture: x86_64
      pxe_loader: PXELinux BIOS
      puppet_ca_proxy: {{ puppet_ca_proxy }}
      puppet_proxy: {{ puppet_proxy }}
      root_pass: whatev3er
      environment: test
      ptable: Centos - LVM - / , swap
      owner: god
      state: present
      validate_certs: false
      delegate_to: localhost

    “msg”: "Failed to connect to Foreman server: StopIteration: "

The issue i have now is it wont connect to create the host.

"msg": "Failed to connect to Foreman server: StopIteration: "

Nick Tailor
nicktailor.com