Ansible-playbook reads roles without parsing variables

Problem:

Expected outcome:

ansible-playbook to be able to parse role variables from the template .j2 files

The roles are located in /etc/ansible/roles. The playbook reads the roles but doesn’t parse the variables.

This is the job template playbook

---

- name: Setup nisso-server-playbooks nodes
  hosts: all
  serial: "{{ serial_number|default('100%') }}"
  become: true

  pre_tasks:
    - name: Set hostname to hostname_override(defaults to inventory_hostname)
      ansible.builtin.hostname:
        name: "{{ hostname_override | default(inventory_hostname) }}"
      tags: hostname

    - name: Remove /var/spool/mail/root if it exists
      ansible.builtin.file:
        path: /var/spool/mail/root
        state: absent
      tags: mail

    - name: Debug all host variables
      ansible.builtin.debug:
        var: hostvars[inventory_hostname]

  roles:
    - role: nisso-server-apps
      tags: nisso-server-apps

  tasks:
    - name: Include additional roles
      ansible.builtin.include_role:
        name: "{{ item }}"
      with_items: "{{ nisso_server_playbooks_additional_roles }}"
      when: nisso_server_playbooks_additional_roles is defined
      tags: additional-roles

The nisso-server-apps role calls up the other roles.

Foreman and Proxy versions:

  • foreman-3.16.1-1.el9.noarch

  • foreman-proxy-3.16.1-1.el9.noarch

  • katello-4.18.1-1.el9.noarch

Foreman and Proxy plugin versions:

  • rubygem-dynflow-1.9.3-1.el9.noarch
  • rubygem-foreman-tasks-11.0.5-1.fm3_16.el9.noarch
  • rubygem-foreman_ansible-17.0.2-1.fm3_16.el9.noarch
  • rubygem-foreman_maintain-1.13.6-1.el9.noarch
  • rubygem-foreman_openscap-11.1.1-1.fm3_16.el9.noarch
  • rubygem-foreman_remote_execution-16.2.3-1.fm3_16.el9.noarch
  • rubygem-foreman_templates-10.0.10-1.fm3_16.el9.noarch
  • rubygem-hammer_cli-3.16.0-1.el9.noarch
  • rubygem-hammer_cli_foreman-3.16.0-1.el9.noarch
  • rubygem-hammer_cli_foreman_openscap-0.2.3-1.fm3_16.el9.noarch
  • rubygem-hammer_cli_foreman_remote_execution-0.3.4-1.fm3_16.el9.noarch
  • rubygem-hammer_cli_foreman_tasks-0.0.24-1.fm3_16.el9.noarch
  • rubygem-hammer_cli_katello-1.18.0-1.el9.noarch
  • rubygem-katello-4.18.1-1.el9.noarch
  • rubygem-pulp_ansible_client-0.24.7-1.el9.noarch
  • rubygem-pulp_certguard_client-3.73.14-1.el9.noarch
  • rubygem-pulp_container_client-2.24.2-2.el9.noarch
  • rubygem-pulp_deb_client-3.5.2-1.el9.noarch
  • rubygem-pulp_file_client-3.73.14-1.el9.noarch
  • rubygem-pulp_ostree_client-2.4.8-1.el9.noarch
  • rubygem-pulp_python_client-3.13.5-1.el9.noarch
  • rubygem-pulp_rpm_client-3.29.5-1.el9.noarch
  • rubygem-pulpcore_client-3.73.14-1.el9.noarch
  • rubygem-smart_proxy_dynflow-0.9.4-1.fm3_14.el9.noarch
  • rubygem-smart_proxy_pulp-3.4.0-1.fm3_13.el9.noarch

Distribution and version:

Other relevant data:

I’m afraid I’m not following what you mean by that.

If you take that, put it into a yaml file and run it with ansible-playbook yourself, does it behave the same way?

1 Like

It does read the roles in /etc/ansible/roles but doesn’t not process the template variables, if there is a part of the template .j2 file that doesn’t have a variable it works, but if there is a variable such as

{% if sshd_kex_algorithms is defined %}
KexAlgorithms {{ sshd_kex_algorithms }}
{% endif %} 

the playbook doesn’t process the variable.

If I run the playbook from /var/lib/foreman-proxy/repositories/repo/playbook it works as expected.

Answer to your second question: That is what I did initially and this is where the problem occurs. On the command line the playbook works as expected but in the foreman ui under hosts/templates/ansible-playbook-name, it works but doesn’t process the roles variables.

As in, the resulting file that gets placed on the disk still contains the {% ... %} parts?

Thank you for your quick response, I’m gathering specific information to save time.