Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2022649 - Hammer unable to send correct value for for Job Templates in order to update ALL packages.
Summary: Hammer unable to send correct value for for Job Templates in order to update ...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Hammer
Version: 6.9.0
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: 6.12.0
Assignee: Oleh Fedorenko
QA Contact: Gaurav Talreja
URL:
Whiteboard:
: 2036446 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-11-12 09:44 UTC by Jaskaran Singh Narula
Modified: 2024-12-20 21:35 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-11-16 13:32:59 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 34079 0 Normal New Hammer unable to send correct value for for Job Templates in order to update ALL packages. 2021-12-03 16:29:23 UTC
Red Hat Issue Tracker SAT-6723 0 None None None 2022-09-28 21:04:57 UTC
Red Hat Product Errata RHSA-2022:8506 0 None None None 2022-11-16 13:33:13 UTC

Description Jaskaran Singh Narula 2021-11-12 09:44:10 UTC
Description of problem:
Using the Job Template i.e "Package Action - Ansible Default" trying to execute a remote execution job to install ALL packages present on the client system. However. it is failing due to the * option used in the hammer command.

If the same Job Template is used through the Satellite Web UI the job works perfectly fine.  
  
It seems when satellite Web UI takes input for the "name" parameter which is *. the value is properly taken. 
But when hammer takes in even with the "*" option it does not go in as * and hence fails.  


Even after changing multiple options for the argument "--name=??" hammer does not send the same value to the satellite.
But in the debug option it looks like it sends but it does not.  

 -----
 [ INFO 2021-11-12T13:46:36 HammerCLIForemanRemoteExecution::JobInvocation::CreateCommand] Called with options: {"option_inputs"=>{"state"=>"latest", "name"=>"\\'*\\",---------------------->>>>>> (VALUE ENTERED HERE...) 
"post_script"=>"needs-restarting -r || shutdown -r +1"}, "option_job_template_name"=>"Package Action - Ansible Default", "option_job_template_id"=>179, "option_search_query"=>"HOSTNAME"}
[ INFO 2021-11-12T13:46:36 API] Server: https://satellite.example.redhat.com
[ INFO 2021-11-12T13:46:36 API] POST /api/job_invocations
[DEBUG 2021-11-12T13:46:36 API] Params: {
    "job_invocation" => {
            "job_template_id" => 179,
                     "inputs" => {
                  "state" => "latest",
                   "name" => "*",        -------------------------->>>>> This is correct Value but this is not correct. 
            "post_script" => "needs-restarting -r || shutdown -r +1"
        },
------


Version-Release number of selected component (if applicable):
satellite 6.9

How reproducible:
100% 

Steps to Reproduce:
1. Run the following command on the satellite cli:
-----
 # hammer -d job-invocation create --job-template "Package Action - Ansible Default" --inputs state="latest",name="*",post_script="needs-restarting -r || shutdown -r +1"  --search-query "client_hostname"
 ------

Actual results:
Using the hammer comment the Job fails every time. There is no way to pass any option to specific "ALL" as an option to update ALL packages. 


Expected results:
Using the hammer command as well this should job should execute properly.  


Additional info:

Comment 1 Adam Ruzicka 2021-11-15 14:34:11 UTC
I'm not sure I follow, it seems to work for me.

Could you run the following and paste the full log and part of production.log from around that time?

hammer -v -d job-invocation create --job-template "Package Action - Ansible Default" \
  --inputs state="latest",name="*",post_script="needs-restarting -r || shutdown -r +1" \
  --search-query "client_hostname"

Also, could you check the same but using json syntax for the inputs?

hammer -v -d job-invocation create --job-template "Package Action - Ansible Default" \
  --inputs '{"state": "latest", "name": "*", "post_script": "needs-restarting -r || shutdown -r +1"}' \
  --search-query "client_hostname"

Comment 2 Adam Ruzicka 2021-11-15 14:48:32 UTC
Oh, ok, the case actually had enough information to go by. If a single asterisk is passed in, the rendered template contains a task definition which looks like this.

    - package:
        name: *
        state: latest

Ansible doesn't like this as it expects the asterisk to be wrapped in quotes. However, hammer apparently strips quotes from inputs so it is tricky to pass the right value. From my point of view, this is a bug in hammer, not REX itself.

The following should work without any code changes.

hammer -v -d job-invocation create --job-template "Package Action - Ansible Default" \
  --inputs '{"state": "latest", "name": "\"*\"", "post_script": "needs-restarting -r || shutdown -r +1"}' \
  --search-query "client_hostname"

Comment 3 Oleh Fedorenko 2021-12-03 16:29:22 UTC
Created redmine issue https://projects.theforeman.org/issues/34079 from this bug

Comment 4 Bryan Kearney 2021-12-04 00:05:37 UTC
Upstream bug assigned to ofedoren

Comment 5 Bryan Kearney 2021-12-04 00:05:39 UTC
Upstream bug assigned to ofedoren

Comment 6 Bryan Kearney 2021-12-13 04:05:24 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/34079 has been resolved.

Comment 7 Oleh Fedorenko 2021-12-13 12:11:01 UTC
The bug was fixed in the upstream and will lend into the next major hammer release (unless someone marks this for CPing).

The one important note: to make the previous command work, one must specify that the quotes in a string are actually required by escaping them with \. Thus, with this fix, the command should look like:

> hammer job-invocation create --job-template "Package Action - Ansible Default" --inputs state=latest,name=\"*\",post_script="needs-restarting -r || shutdown -r +1"  --search-query "client_hostname"

Comment 8 Oleh Fedorenko 2022-01-03 16:07:13 UTC
*** Bug 2036446 has been marked as a duplicate of this bug. ***

Comment 10 Gaurav Talreja 2022-09-28 21:02:35 UTC
Hi,

Tested this on Satellite 6.12.0 Snap 12.0 with rubygem-hammer_cli-3.3.0-1.el8sat.noarch

1. Setup Satellite, register a content_host and configure REX
2. Try following commands with yaml and json syntax to update all packages with asterisk wrapped in quotes 
# hammer -v -d job-invocation create --job-template "Package Action - Ansible Default" --inputs state="latest",name="\"*\"",post_script="needs-restarting -r || shutdown -r +1" --search-query name~client_hostname
# hammer -v -d job-invocation create --job-template "Package Action - Ansible Default" --inputs '{"state": "latest", "name": "\"*\"", "post_script": "needs-restarting -r || shutdown -r +1"}' --search-query name~client_hostname
# hammer -v -d job-invocation create --job-template "Package Action - Ansible Default" --inputs state=latest,name=\"*\",post_script="needs-restarting -r || shutdown -r +1" --search-query name~client_hostname

Observations:
Using the above commands, all packages have been updated on the client with the asterisk escaped in the name input.

Furthermore, I've noticed that REX commands are used differently with 6.12, such as when testing "Run Command - Ansible Default" job template with input passed as --inputs="command=\'useradd -m testuser\'". Despite starting, the job failed because it attempted to run \'useradd -m testuser\' literally with the backslashes on the client, where hammer added one more slash //'useradd -m sZCNyGDzws//', which was not the case with 6.11.

However, it works fine if input is passed as --inputs="command=useradd -m testuser", so I would like to check if this is expected behavior of this command? If not, Do you think we can move this BZ back to ASSIGNED??


Thanks,
Gaurav

Comment 11 Adam Ruzicka 2022-10-03 15:30:11 UTC
This is a bit tricky. On one hand I'd say --inputs "command='foo'" should be treated as foo in single quotes hence the new behavior is correct, on the other hand, I'm not sure how multiple inputs are now distinguished. I'll defer to Oleh

Comment 12 Brad Buckingham 2022-10-04 11:43:59 UTC
Adding needinfo for Oleh based upon comment 11 ("defer to Oleh").

Oleh, can you look over this bugzilla and provide your input?

Comment 13 Oleh Fedorenko 2022-10-04 17:45:33 UTC
Hello,

Answering on https://bugzilla.redhat.com/show_bug.cgi?id=2022649#c10: yes, this is expected behavior now.

Comment 14 Gaurav Talreja 2022-10-06 09:22:29 UTC
Oleh, Thanks for confirming, moving this BZ to verified.

Comment 18 errata-xmlrpc 2022-11-16 13:32:59 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 (Important: Satellite 6.12 Release), 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-2022:8506


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