How to output in different formats using hammer
Environment
- Red Hat Satellite 6
Issue
- How to ignore formatting via hammer and output in different formats
Resolution
- The following the options that are possible with hammer
hammer -h
Options:
--autocomplete LINE Get list of possible endings
--csv Output as CSV (same as --output=csv)
--csv-separator SEPARATOR Character to separate the values
--interactive INTERACTIVE Explicitly turn interactive mode on/off
One of true/false, yes/no, 1/0.
--output ADAPTER Set output format. One of [yaml, base, table, json, csv, silent]
--show-ids Show ids of associated resources
--version show version
Some Examples:
hammer --csv task list --per-page 10
Id,Name,Owner,Started at,Ended at,State,Result,Task action,Task errors
33b3c87a-44dd-43a1-af17-d09584ca626f,,foreman_admin,2015/11/07 17:23:45,2015/11/07 17:23:47,stopped,success,Update,""
a59f0d51-5c1c-4fbd-ba8d-ab8fbb906e28,,foreman_admin,2015/11/07 17:22:04,2015/11/07 17:22:06,stopped,success,Update,""
c014396c-f57c-4307-9496-df5d204270d0,,foreman_admin,2015/11/07 17:21:45,2015/11/07 17:21:47,stopped,success,Generate applicability,""
23ecf01a-5366-44d7-b88a-250853b98c1a,,foreman_admin,2015/11/07 17:20:24,2015/11/07 17:20:26,stopped,success,Generate applicability,""
7be38f22-acd1-44ae-9734-e9e3c5486cb0,,foreman_admin,2015/11/07 17:20:04,2015/11/07 17:20:06,stopped,success,Generate applicability,""
7e4d163b-4f68-489e-958f-966500ae3e7c,,foreman_admin,2015/11/07 17:19:58,2015/11/07 17:20:00,stopped,success,Generate applicability,""
7fd4bdfd-3c3c-4136-955b-4fff28c1b2f2,,foreman_admin,2015/11/07 17:18:04,2015/11/07 17:18:06,stopped,success,Generate applicability,""
dde48b5d-1809-4e5a-8732-8da692b47153,,foreman_admin,2015/11/07 17:16:55,2015/11/07 17:16:56,stopped,success,Generate applicability,""
da856d74-ddeb-4a7c-aaeb-6c97d3799a98,,foreman_admin,2015/11/07 17:16:35,2015/11/07 17:16:36,stopped,success,Generate applicability,""
830a7968-b3e6-4c5b-8d07-de38aa8c5bc2,,foreman_admin,2015/11/07 17:16:24,2015/11/07 17:16:29,stopped,success,Create,""
- Or using hammer csv with a seperator.
hammer --csv --csv-separator ' .. ' task list --per-page 10
Id .. Name .. Owner .. "Started at" .. "Ended at" .. State .. Result .. "Task action" .. "Task errors"
33b3c87a-44dd-43a1-af17-d09584ca626f .. .. foreman_admin .. "2015/11/07 17:23:45" .. "2015/11/07 17:23:47" .. stopped .. success .. Update .. ""
a59f0d51-5c1c-4fbd-ba8d-ab8fbb906e28 .. .. foreman_admin .. "2015/11/07 17:22:04" .. "2015/11/07 17:22:06" .. stopped .. success .. Update .. ""
c014396c-f57c-4307-9496-df5d204270d0 .. .. foreman_admin .. "2015/11/07 17:21:45" .. "2015/11/07 17:21:47" .. stopped .. success .. "Generate applicability" .. ""
23ecf01a-5366-44d7-b88a-250853b98c1a .. .. foreman_admin .. "2015/11/07 17:20:24" .. "2015/11/07 17:20:26" .. stopped .. success .. "Generate applicability" .. ""
7be38f22-acd1-44ae-9734-e9e3c5486cb0 .. .. foreman_admin .. "2015/11/07 17:20:04" .. "2015/11/07 17:20:06" .. stopped .. success .. "Generate applicability" .. ""
7e4d163b-4f68-489e-958f-966500ae3e7c .. .. foreman_admin .. "2015/11/07 17:19:58" .. "2015/11/07 17:20:00" .. stopped .. success .. "Generate applicability" .. ""
7fd4bdfd-3c3c-4136-955b-4fff28c1b2f2 .. .. foreman_admin .. "2015/11/07 17:18:04" .. "2015/11/07 17:18:06" .. stopped .. success .. "Generate applicability" .. ""
dde48b5d-1809-4e5a-8732-8da692b47153 .. .. foreman_admin .. "2015/11/07 17:16:55" .. "2015/11/07 17:16:56" .. stopped .. success .. "Generate applicability" .. ""
da856d74-ddeb-4a7c-aaeb-6c97d3799a98 .. .. foreman_admin .. "2015/11/07 17:16:35" .. "2015/11/07 17:16:36" .. stopped .. success .. "Generate applicability" .. ""
830a7968-b3e6-4c5b-8d07-de38aa8c5bc2 .. .. foreman_admin .. "2015/11/07 17:16:24" .. "2015/11/07 17:16:29" .. stopped .. success .. Create .. ""
- Or you can output the format into other formats such as yaml/JSON.
hammer --csv --csv-separator ' .. ' --output yaml task list --per-page 10
---
- State: stopped
Ended at: "2015-11-07T17:23:47Z"
Started at: "2015-11-07T17:23:45Z"
Task errors: []
Owner: foreman_admin
Name:
Id: 33b3c87a-44dd-43a1-af17-d09584ca626f
Result: success
Task action: Update
- State: stopped
Ended at: "2015-11-07T17:22:06Z"
Started at: "2015-11-07T17:22:04Z"
Task errors: []
Owner: foreman_admin
Name:
Id: a59f0d51-5c1c-4fbd-ba8d-ab8fbb906e28
Result: success
Task action: Update
- State: stopped
Ended at: "2015-11-07T17:21:47Z"
Started at: "2015-11-07T17:21:45Z"
Task errors: []
hammer --output json content-export list --organization-id 1 --fields "Id,Type,content view version"
[
{
"ID": 1,
"Type": "complete",
"Content View Version": "Test 1.0"
},
{
"ID": 2,
"Type": "complete",
"Content View Version": "Test 1.0"
},
{
"ID": 3,
"Type": "complete",
"Content View Version": "Test 1.0"
},
{
"ID": 4,
"Type": "complete",
"Content View Version": "Test 1.0"
}
]
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments