Bug 1574461 - when running ansible playbook on host, debug message is not printed
Summary: when running ansible playbook on host, debug message is not printed
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite 6
Classification: Red Hat
Component: Ansible
Version: 6.4
Hardware: Unspecified
OS: Unspecified
unspecified
low vote
Target Milestone: 6.6.0
Assignee: Ondřej Pražák
QA Contact: Lukas Pramuk
URL:
Whiteboard:
Depends On:
Blocks: 1449011
TreeView+ depends on / blocked
 
Reported: 2018-05-03 11:21 UTC by Jan Hutař
Modified: 2019-10-22 19:48 UTC (History)
5 users (show)

Fixed In Version: tfm-rubygem-foreman_ansible-3.0.5
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-10-22 19:48:52 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Foreman Issue Tracker 25462 Normal Closed When running Ansible roles on host, debug message is not printed 2020-01-16 15:08:49 UTC

Description Jan Hutař 2018-05-03 11:21:22 UTC
Description of problem:
When running ansible playbook on host, debug message which is supposed to contain parameters coming from Foreman is not fully printed


Version-Release number of selected component (if applicable):
satellite-6.4.0-3.beta.el7sat.noarch
ansible-2.4.2.0-2.el7.noarch
rubygem-smart_proxy_ansible-2.0.2-3.el7sat.noarch
tfm-rubygem-foreman_ansible-2.0.4-1.el7sat.noarch
tfm-rubygem-foreman_ansible_core-2.0.2-1.el7sat.noarch


How reproducible:
always


Steps to Reproduce:
1. Have a Sat with ansible role imported (I have used "linuxhq.setup"
   from Galaxy)
2. Add host parameter "setup_motd: Hello world"
3. Click "Run Ansible roles" button


Actual results:
TASK [debug] *******************************************************************
ok: [rhel74.example.com] => {
  "msg": "These"
}


Expected results:
Whole message with params should be printed


Additional info:
[root@sat640snap1 ~]# cat /tmp/foreman-playbook-48454835-a67f-4b5f-ad57-075074e3e467.yml 
---
- hosts: rhel74.example.com
  tasks:
    - debug: msg=These are the parameters "{{ foreman_params }}"
  roles:
        - linuxhq.setup
[root@sat640snap1 ~]# cat /tmp/foreman-inventories/48454835-a67f-4b5f-ad57-075074e3e467 | json_reformat 
{
    "all": {
        "hosts": [
            "rhel74.example.com"
        ],
        "vars": {

        }
    },
    "_meta": {
        "hostvars": {
            "rhel74.example.com": {
                "foreman": {
                    "ip": "192.168.122.223",
                    "ip6": "",
                    "environment_id": null,
                    "environment_name": null,
                    "last_report": null,
                    "mac": "52:54:00:b4:11:58",
                    "realm_id": null,
                    "realm_name": null,
                    "sp_mac": null,
                    "sp_ip": null,
                    "sp_name": null,
                    "domain_id": 1,
                    "domain_name": "example.com",
                    "architecture_id": 1,
                    "architecture_name": "x86_64",
                    "operatingsystem_id": 2,
                    "operatingsystem_name": "RedHat 7.4",
                    "subnet_id": null,
                    "subnet_name": null,
                    "subnet6_id": null,
                    "subnet6_name": null,
                    "sp_subnet_id": null,
                    "ptable_id": null,
                    "ptable_name": null,
                    "medium_id": null,
                    "medium_name": null,
                    "pxe_loader": null,
                    "build": false,
                    "comment": "",
                    "disk": null,
                    "installed_at": null,
                    "model_id": 1,
                    "hostgroup_id": null,
                    "owner_id": 4,
                    "owner_name": "Admin User",
                    "owner_type": "User",
                    "enabled": true,
                    "managed": false,
                    "use_image": null,
                    "image_file": "",
                    "uuid": null,
                    "compute_resource_id": null,
                    "compute_resource_name": null,
                    "compute_profile_id": null,
                    "compute_profile_name": null,
                    "capabilities": [
                        "build"
                    ],
                    "provision_method": "build",
                    "certname": "rhel74.example.com",
                    "image_id": null,
                    "image_name": null,
                    "created_at": "2018-05-02T12:52:14.722Z",
                    "updated_at": "2018-05-03T10:35:13.000Z",
                    "last_compile": "2018-05-02T18:59:36.000Z",
                    "global_status": 2,
                    "global_status_label": "Error",
                    "organization_id": 1,
                    "organization_name": "Default Organization",
                    "location_id": 2,
                    "location_name": "Default Location",
                    "puppet_status": 0,
                    "model_name": "Standard PC (i440FX + PIIX, 1996)",
                    "execution_status": 0,
                    "execution_status_label": "Last execution succeeded",
                    "errata_status": 1,
                    "errata_status_label": "Could not calculate errata status, ensure host is registered and the katello-host-tools package is installed",
                    "subscription_status": 2,
                    "subscription_status_label": "Unentitled",
                    "name": "rhel74.example.com",
                    "id": 2,
                    "puppet_proxy_id": null,
                    "puppet_proxy_name": null,
                    "puppet_ca_proxy_id": null,
                    "puppet_ca_proxy_name": null,
                    "openscap_proxy_id": null,
                    "openscap_proxy_name": null,
                    "puppet_proxy": null,
                    "puppet_ca_proxy": null,
                    "openscap_proxy": null,
                    "hostgroup_name": null,
                    "hostgroup_title": null,
                    "content_facet_attributes": {
                        "id": 1,
                        "uuid": "3e79fe01-aff4-462d-9780-1c4d685ab02a",
                        "content_view_id": 1,
                        "content_view_name": "Default Organization View",
                        "lifecycle_environment_id": 1,
                        "lifecycle_environment_name": "Library",
                        "content_source_id": null,
                        "content_source_name": null,
                        "kickstart_repository_id": null,
                        "kickstart_repository_name": null,
                        "errata_counts": {
                            "security": 0,
                            "bugfix": 0,
                            "enhancement": 0,
                            "total": 0
                        },
                        "applicable_package_count": 0,
                        "upgradable_package_count": 0,
                        "content_view": {
                            "id": 1,
                            "name": "Default Organization View"
                        },
                        "lifecycle_environment": {
                            "id": 1,
                            "name": "Library"
                        },
                        "content_source": null,
                        "kickstart_repository": null
                    },
                    "subscription_global_status": 2,
                    "subscription_facet_attributes": {
                        "id": 3,
                        "uuid": "3e79fe01-aff4-462d-9780-1c4d685ab02a",
                        "last_checkin": "2018-05-03T10:12:49.144Z",
                        "service_level": "",
                        "release_version": null,
                        "autoheal": true,
                        "registered_at": "2018-05-02T13:28:29.000Z",
                        "registered_through": "sat640snap1.example.com",
                        "user": {
                            "id": 4,
                            "login": "admin"
                        }
                    }
                },
                "foreman_params": {
                    "setup_moth": "Hello world",
                    "remote_execution_ssh_keys": [
                        "ssh-rsa A...D foreman-proxy@sat640snap1.example.com"
                    ],
                    "remote_execution_ssh_user": "root",
                    "remote_execution_effective_user_method": "sudo",
                    "remote_execution_connect_by_ip": false
                },
                "foreman_ansible_roles": [
                    "linuxhq.setup"
                ],
                "ansible_connection": "ssh",
                "ansible_ssh_private_key_file": "~/.ssh/id_rsa_foreman_proxy",
                "ansible_winrm_server_cert_validation": "validate",
                "ansible_become": null,
                "ansible_user": "root",
                "ansible_ssh_pass": null,
                "ansible_port": "22",
                "ansible_ssh_port": "22",
                "ansible_ssh_user": "root",
                "remote_execution_ssh_user": "root",
                "remote_execution_effective_user_method": "sudo"
            }
        }
    }
}

Comment 2 Martin Korbel 2018-05-29 10:51:02 UTC
This problem is already solved in snap_6.4.0_5.0.

I little edit topic of this bug.

This debug works only when the playbook is pass. When there is a problem (in roles), debug of variables does not work.  Ansible executes roles at first and tasks after that. When we change tasks to pre_tasks, it is executed before roles and we can debug varibales.

ORIGINAL:
tasks:
    - name: Display all parameters known for the Foreman host
      debug:
        var: foreman_params
...

----------------------
NEW VERSION:
pre_tasks:
    - name: Display all parameters known for the Foreman host
      debug:
        var: foreman_params
...

Comment 3 Ondřej Pražák 2018-11-14 12:47:23 UTC
Created redmine issue http://projects.theforeman.org/issues/25462 from this bug

Comment 4 Bryan Kearney 2019-03-05 17:00:38 UTC
Upstream bug assigned to oprazak@redhat.com

Comment 5 Bryan Kearney 2019-03-05 17:00:39 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue https://projects.theforeman.org/issues/25462 has been resolved.

Comment 11 Lukas Pramuk 2019-07-17 09:03:19 UTC
FailedQA.

@Satellite-6.6.0 Snap9
tfm-rubygem-foreman_ansible-3.0.3-3.el7sat.noarch

# sed 1,11d /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_ansible-*/app/views/foreman_ansible/job_templates/ansible_roles_-_ansible_default.erb
---
- hosts: all
  pre_tasks:
    - name: Display all parameters known for the Foreman host
      debug:
        var: foreman_params
  roles:
<%- if @host.all_ansible_roles.present? -%>
<%=   @host.all_ansible_roles.map { |role| "    - #{role.name.strip}" }.join("\n") %>
<%- end -%>

>>> the fix (debug in pre_tasks) made it into compose

-------
   1:
   2:PLAY [all] *********************************************************************
   3:
   4:TASK [Gathering Facts] *********************************************************
   5:ok: [host1.example.com]
   6:
   7:TASK [Display all parameters known for the Foreman host] ***********************
   8:ok: [host1.example.com] => {
   9:    "foreman_params": "VARIABLE IS NOT DEFINED!"
  10:}
  11:PLAY RECAP *********************************************************************
  12:host1.example.com : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
  13:Exit status: 0
------

>>> debug msg is quite useless "foreman_params": "VARIABLE IS NOT DEFINED!"

Comment 12 Lukas Pramuk 2019-07-17 09:29:20 UTC
in Snap10

Comment 13 Ondřej Pražák 2019-07-17 11:39:50 UTC
Connecting redmine issue https://projects.theforeman.org/issues/27317 from this bug

Comment 14 Ondřej Pražák 2019-07-17 11:42:55 UTC
The job template was not updated, the fix is to use 'foreman' instead of 'foreman_params' as a debug var.

Comment 18 Lukas Pramuk 2019-09-05 17:29:21 UTC
VERIFIED.

@Satellite 6.6.0 Snap18
tfm-rubygem-foreman_ansible-3.0.6-2.el7sat.noarch

------
 1: 
 2: PLAY [all] *********************************************************************
 3: 
 4: TASK [Gathering Facts] *********************************************************
 5: ok: [host1.example.com]
 6: 
 7: TASK [Display all parameters known for the Foreman host] ***********************
 8: ok: [host1.example.com] => 
 9:   foreman:
10:     content_view: Default_Organization_View
11:     content_view_info:
12:       components: {}
13:       label: Default_Organization_View
14:       latest-version: '1.0'
15:       published: '2019-08-28T15:52:17.821Z'
16:       version: '1.0'
17:     domainname: example.com
18:     foreman_config_groups: []
19:     foreman_host_collections: []
20:     foreman_interfaces:
21:     - attached_to: null
22:       attrs:
23:         active: true
24:         device: ens3
25:         features:
26:           busy_poll: off [fixed]
27:           fcoe_mtu: off [fixed]
....

188: PLAY RECAP *********************************************************************
189: host1.example.com : ok=14   changed=0    unreachable=0    failed=0    skipped=6    rescued=0    ignored=0   
190:
191: Exit status: 0

>>> there is quite verbose debug info for the host play

Comment 19 Bryan Kearney 2019-10-22 19:48:52 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2019:3172


Note You need to log in before you can comment on or make changes to this bug.