theforeman / foreman-ansible-modules

Ansible modules for interacting with the Foreman API and various plugin APIs such as Katello
GNU General Public License v3.0
146 stars 163 forks source link

foreman_provisioning_template returns "changed" always #590

Closed itcultus closed 4 years ago

itcultus commented 4 years ago
SUMMARY

I use the under subject module in order to create/update/delete my provisioning templates. I have them as variables in a roles var file.

ISSUE TYPE
ANSIBLE VERSION
ansible 2.8.6
  config file = /home/ptselios/Documents/Projects/Bosch/bsc-git/bosch-private-cloud/ansible.cfg
  configured module search path = ['/home/ptselios/Documents/Projects/Bosch/bsc-git/bosch-private-cloud/library', '/home/ptselios/Documents/Projects/Bosch/bsc-git/bosch-private-cloud/imported/ceph-ansible/library']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.5 (default, Oct 17 2019, 12:21:00) [GCC 8.3.1 20190223 (Red Hat 8.3.1-2)]
KATELLO/FOREMAN VERSION
tfm-rubygem-katello-3.10.0.55-1.el7sat.noarch
foreman-1.20.1.35-1.el7sat.noarch
APYPIE VERSION
python3-apypie-0.1.0-1.fc29.noarch
python2-apypie-0.1.0-1.fc29.noarch
STEPS TO REPRODUCE

defaults/main.yml:

---
- name: Configure Satellite 
  become: false
  gather_facts: true
  hosts: satellite
  vars:
  provisioning_templates
    - name: "create_sudoer_user"
      locations:
        - "location_1"
        - "location_2"
      organizations:
        - "{{ org }}"
      kind: "snippet"
      locked: no
      state: present
      template: |
        <%#
        name: create_users
        model: ProvisioningTemplate
        kind: snippet
        snippet: true
        -%>
        <%- users = @host.owner_type == 'Usergroup' ? @host.owner.all_users : [@host.owner] -%>
        <%- users.each do |user| -%>
        <%=   "useradd #{user.login}" %>
        <%-   if user.respond_to?(:ssh_authorized_keys) && user.ssh_authorized_keys.any? -%>
        <%=     "mkdir -p -m 0700 ~#{user.login}/.ssh" %>
        <%=     "cat >> ~#{user.login}/.ssh/authorized_keys <<EOF" %>
        <%-     index = 0 -%>
        <%-     user.ssh_keys.each do |key| -%>
        <%-       if index == 0 -%>
        <%=        "#{key.type} #{key.ssh_key} #{key.comment}" %>
        <%-       else -%>
        <%=        "#{key.type} #{key.ssh_key} #{key.comment} - #{index}" %>
        <%-       end -%>
        <%-       index += 1 -%>
        <%-     end -%>
        <%=     "EOF" %>
        <%=     "chown -R #{user.login}:#{user.login} ~#{user.login}/.ssh" %>
        <%=     "chmod -R go= ~#{user.login}/.ssh" %>
        <%=     "echo  \"#{user.login}  ALL=(ALL) NOPASSWD: ALL\" > /etc/sudoers.d/#{user.login}" %>
        <%-   end -%>
        <%- end %>      
  tasks:
    - name: Create Provisioning Templates
      theforeman.foreman.foreman_provisioning_template:
        username: "{{ satellite_admin }}"
        password: "{{ satellite_admin_password }}"
        server_url: "{{ satellite_server_url }}"
        validate_certs: "{{ validate_certs }}"
        audit_comment: "{{ item.audit_comment | default(audit_comment) }}"
        file_name: "{{ item.file_name | default(omit) }}"
        kind: "{{ item.kind | default('snippet') }}"
        locations: "{{ item.locations | default(all_locations) }}"
        locked: "{{ item.locked | default(omit) }}"
        name: "{{ item.name }}"
        operatingsystems: "{{ item.operatingsystems | default(omit) }}"
        state: "{{ item.state | default('present') }}"
        template: "{{ item.template | default(omit) }}"
        organizations: "{{ item.organizations | default(org) }}"
      loop: "{{ provisioning_templates }}"
EXPECTED RESULTS

I would expect OK on the second run of this playbook.

ACTUAL RESULTS

Playbook recap says "changed: 1"

evgeni commented 4 years ago

notes from triage: this might be whitespace related. I will try to reproduce this. did you tried using a file instead of an inline template?

itcultus commented 4 years ago

No, I can try though. I will return next week.

evgeni commented 4 years ago

so it was not the whitespace, but the audit_comment param. investigating why.

evgeni commented 4 years ago

so the api always returns audit_comment: null and I beginning to think it should not be part of the entity at all. the comment is properly stored in the audit accompanying the change, but it's not really part of the template.

evgeni commented 4 years ago

opened https://projects.theforeman.org/issues/28332 and https://projects.theforeman.org/issues/28333 to track that in foreman and rex, #611 contains a fix for us.