Skip to content

foreman_os_default_template: "AttributeError: 'list' object has no attribute 'get'" #27

Closed as not planned
@stintel

Description

@stintel

The foreman_os_default_template module doesn't seem to work.

Example playbook:

---
- name: Configure Foreman master via API
  hosts: localhost
  connection: local
  tasks:
    - name: add operating system default templates
      foreman_os_default_template:
        operatingsystem: Ubuntu
        config_template: Preseed default
        template_kind: provision
        state: present
        foreman_host: "{{ foreman_host }}"
        foreman_port: "{{ foreman_port }}"
        foreman_user: "{{ foreman_user }}"
        foreman_pass: "{{ foreman_pass }}"

Results in this error:

An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/home/stijn/.ansible/tmp/ansible-tmp-1461933187.79-89398459364617/foreman_os_default_template", line 2115, in <module>
    main()
  File "/home/stijn/.ansible/tmp/ansible-tmp-1461933187.79-89398459364617/foreman_os_default_template", line 175, in main
    changed, os_default_template = ensure()
  File "/home/stijn/.ansible/tmp/ansible-tmp-1461933187.79-89398459364617/foreman_os_default_template", line 112, in ensure
    os_default_templates = theforeman.get_operatingsystem_default_templates(id=os.get('id'))
AttributeError: 'list' object has no attribute 'get'

fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "foreman_os_default_template"}, "parsed": false}

This happens because I have >1 Ubuntu versions in Foreman. In this case, search_operatingsystem returns a list. Removing either of them solves the issue.

>>> os = theforeman.search_operatingsystem(data=dict(name='Ubuntu'))
>>> print os
[{u'major': u'14', u'description': None, u'family': u'Debian', u'title': u'Ubuntu 14.04', u'created_at': u'2016-04-28 15:11:48 UTC', u'updated_at': u'2016-04-29 10:00:34 UTC', u'name': u'Ubuntu', u'release_name': u'trusty', u'id': 11, u'minor': u'04', u'password_hash': u'SHA256'}, {u'major': u'16', u'description': None, u'family': u'Debian', u'title': u'Ubuntu 16.04', u'created_at': u'2016-04-28 15:11:48 UTC', u'updated_at': u'2016-04-29 10:00:34 UTC', u'name': u'Ubuntu', u'release_name': u'xenial', u'id': 12, u'minor': u'04', u'password_hash': u'SHA256'}]
>>> type(os)
<type 'list'>

vs

>>> os = theforeman.search_operatingsystem(data=dict(name='Ubuntu'))
>>> print os
{u'major': u'16', u'description': None, u'family': u'Debian', u'title': u'Ubuntu 16.04', u'created_at': u'2016-04-28 15:11:48 UTC', u'updated_at': u'2016-04-29 10:00:34 UTC', u'name': u'Ubuntu', u'release_name': u'xenial', u'id': 12, u'minor': u'04', u'password_hash': u'SHA256'}
>>> type(os)
<type 'dict'>

Reporting it here as I'm not sure how to fix this yet. Maybe someone else has a great idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions