Theforeman.foreman.host is not a valid attribute for a Play

I installed the collection theforeman.foreman and upgraded to ansible-galaxy 2.10 so the collection is listed when I query ansible-galaxy. But using the example code in Foreman :: Plugin documentation index I get the error
‘theforeman.foreman.host’ is not a valid attribute for a Play
What am I doing wrong?

It seems that you placed the module name outside of the task, check it with the code below (this is a task to create a user, different module, same principle):

- name: 'Example'
  hosts: 'foreman'
  tasks:
   - name: 'Create user for Ansible'
      theforeman.foreman.user:
        username: 'admin'
        password: 'secretadminpassword'
        server_url: 'https://foreman.example.com'
        validate_certs: false
        name: ansible
        user_password: 'automation_rocks'
        auth_source: 'Internal'
        admin: false
        firstname: 'Ansible'
        lastname: 'Automation'
        mail: 'root@localhost'
        timezone: 'Amsterdam'
        roles:
          - 'Viewer'
          - 'View hosts'
        organizations:
          - 'Default Organization'
        locations: 
          - 'Default Location'
        state: 'present'
1 Like

Hey,

Could you post the whole playbook you’re using? I guess you have a syntax error somewhere around the tasks list.

The whole playbook should look something like this:

- hosts: localhost
  tasks:
    - theforeman.foreman.host:
        server_url: https://foreman.example.com
        …
1 Like

Thanks - I had an issue with the placement of the collection name.

1 Like