Nosmoht / ansible-module-foreman

Ansible module to manage configuration of Foreman
49 stars 32 forks source link

Add support for updating a host #75

Closed mark-wagner closed 6 years ago

mark-wagner commented 6 years ago

Fixes #62. Underlying foreman python module needs to be updated as well. See PR https://github.com/Nosmoht/python-foreman/pull/33 for that.

mark-wagner commented 6 years ago

I restructured the code in foreman_host.py to be similar to foreman_hostgroup.py, which supports updates. I ran one playbook that successfully changed the OS for a host. Ship it!

mark-wagner commented 6 years ago

Working with this change some more I have discovered that the logic to determine if an update is needed is faulty, resulting in an update every time the task is run. Issues discovered (may be foreman / ansible version dependent):

filter_host converts ids to strings. In my version of foreman this is incorrect as the ids returned by get_host in the underlying python-foreman module are integers. Also, it filters out everything that does not end in _id (or 'title', 'name', 'root_pass) but it should not filter out build or enable for example. Simply removing this function will solve all these problems.

if not all(data.get(key, None) == cmp_host.get(key, None) for key in data.keys() + cmp_host.keys()): should not be iterating over data.keys() + cmp_host.keys()) but rather only data.keys() since that is the list of only things that are changing and cmp_host has all the keys (filtered) for the host.

I'll test these changes some more.