<blockquote>
<p><em>Supermicro offers this Redfish Reference Guide, which describes its Redfish REST API in detail.</em></p>
</blockquote>
<p>Right. According the documentation you've referenced, Ch. 4 &quot;<em>Using RESTful APIs</em>&quot; p. 13 ff., the structure of the REST API call seems to be</p>
<pre class="lang-sh prettyprint-override"><code>https://${URL}/redfish/v1/${CATEGORY} ...
</code></pre>
<p>followed by further actions, commands, tasks or payloads.</p>
<blockquote>
<p><em>Can someone explain how to map the API options to the Ansible modules?</em></p>
</blockquote>
<p>After looking up the module documentation examples and the source code</p>
<ul>
<li><a href="https://github.com/ansible-collections/community.general/blob/main/plugins/modules/redfish_config.py" rel="nofollow noreferrer"><code>plugins/modules/redfish_config.py</code></a></li>
<li><a href="https://github.com/ansible-collections/community.general/blob/main/plugins/modules/redfish_command.py" rel="nofollow noreferrer"><code>plugins/modules/redfish_command.py</code></a></li>
</ul>
<p>it turns out that the modules using</p>
<ul>
<li><a href="https://github.com/ansible-collections/community.general/blob/main/plugins/module_utils/redfish_utils.py" rel="nofollow noreferrer"><code>plugins/module_utils/redfish_utils.py</code></a></li>
</ul>
<p>as a wrapper the utilize the REST API. It maps the REST API structure to the parameter structure of the modules (<code>category</code>, <code>command</code>, <code>payload</code>). For a better understanding you may have a look into the mentioned source.</p>
<blockquote>
<p><em>How can I use the Ansible modules to set the hostname or to provide NTP settings?</em></p>
</blockquote>
<p><a href="https://github.com/ansible-collections/community.general/blob/main/plugins/module_utils/redfish_utils.py#L2729" rel="nofollow noreferrer">According the source</a> it seems to be the <code>manager_services</code> for NTP. Because of the lack of the specific environment I'm not able to investigate this further and to do tests, therefore for how to use it you may also have a look into the source.</p>
<p>To get familar with the Redfish RESTful API you may also have a look into <a href="https://github.com/DMTF/Redfishtool" rel="nofollow noreferrer">DMTF Redfishtool</a> it</p>
<blockquote>
<p><em>was originally written during the development of the Redfish specification to help find ambiguities in the spec.</em></p>
</blockquote>
<p><strong>Further Examples</strong></p>
<p>There are some explanations and a general programming example from a bigger production environment available</p>
<ul>
<li>Krenn Wiki <a href="https://www-thomas--krenn-com.translate.goog/de/wiki/Redfish?_x_tr_sl=de&amp;_x_tr_tl=en&amp;_x_tr_hl=de&amp;_x_tr_pto=wapp" rel="nofollow noreferrer">Redfish</a></li>
</ul>
<p><strong>Documentation</strong></p>
<ul>
<li><a href="https://www.dmtf.org/sites/default/files/standards/documents/DSP2060_1.0.0.pdf" rel="nofollow noreferrer">Redfish User Guide</a></li>
</ul>

CC BY-SA 4.0
2022-12-04T09:53:32.280Z
2022-12-04T16:14:52.050Z
2022-12-04T16:14:52.050Z
U880D
<p>As outlined in <a href="https://devops.stackexchange.com/a/17012/34805">U880D's helpful answer</a>, you currently really have to dig down into the code to get working examples for Ansible's Redfish modules.</p>
<p>As a rule of thumb, I recommend to look at the info you can <em>get</em>, to get an idea of info you can probably <em>set</em>. Use both the Supermicro Redfish docs and the <a href="https://docs.ansible.com/ansible/latest/collections/community/general/redfish_info_module.html" rel="nofollow noreferrer">redfish_info module</a> to see what you can get. Be aware, the results are not identical and neither the former nor the latter is more complete than the other. The two examples below will highlight some differences.</p>
<p>The &quot;commands&quot; used by the Ansible modules cannot be found in the Supermicro/Redfish docs. They are synonyms for certain API URIs. You have to look them up in the code, e. g. <a href="https://github.com/ansible-collections/community.general/blob/74c15c12418bf2f7e1dcac1a88657c8aefaeeb6d/plugins/modules/redfish_config.py#L368" rel="nofollow noreferrer">here</a> and try to map them to the Supermicro/Redfish docs. Or dig down deeper to get to the functions that compose the URLs.</p>
<h1>Hostname</h1>
<p>From the <a href="https://www.supermicro.com/manuals/other/redfish-ref-guide-html/Content/general-content/network-management.htm" rel="nofollow noreferrer">Supermicro docs</a>, you can see that there is a property called <code>HostName</code>:</p>
<blockquote>
<pre><code>URI: /redfish/v1/Managers/1/EthernetInterfaces/1
Method: GET
Response: 200
{
    ...
    &quot;MTUSize&quot;: 1500,
    &quot;HostName&quot;: &quot;local&quot;,
    &quot;FQDN&quot;: &quot;local.supermicro.com&quot;,
    ...
}
</code></pre>
</blockquote>
<p>FYI, querying the same info with Ansible, e. g.:</p>
<pre class="lang-yaml prettyprint-override"><code>- name: Get nic info
  community.general.redfish_info:
    category: Manager
    command: GetManagerNicInventory
    baseuri: &quot;{{ baseuri }}&quot;
    username: &quot;{{ username }}&quot;
    password: &quot;{{ password }}&quot;
  register: result

- debug:
    var: result
</code></pre>
<p>will not return a &quot;hostname&quot; property (output omitted). So a win for the Supermicro docs...</p>
<p>Fortunately, you can still <em>set</em> the hostname with Ansible:</p>
<pre class="lang-yaml prettyprint-override"><code>- name: Set hostname
  community.general.redfish_config:
    category: Manager
    command: SetManagerNic
    nic_config:
      HostName: MyHostname
    baseuri: &quot;{{ baseuri }}&quot;
    username: &quot;{{ username }}&quot;
    password: &quot;{{ password }}&quot;
</code></pre>
<h1>NTP</h1>
<p>The <a href="https://www.supermicro.com/manuals/other/redfish-ref-guide-html/Content/general-content/bmc-configuration-examples.htm" rel="nofollow noreferrer">Supermicro docs</a> show the following NTP properties:</p>
<blockquote>
<pre><code>URI: /redfish/v1/Managers/1/Oem/Supermicro/NTP
Method: PATCH
Payload:
{
    &quot;NTPEnable&quot;: true,
    &quot;PrimaryNTPServer&quot;:&quot;127.0.0.1&quot;,
    &quot;SecondaryNTPServer&quot;:&quot;127.0.0.1&quot;,
    &quot;DaylightSavingTime&quot;: false
}
</code></pre>
</blockquote>
<p>But with the following Ansible tasks:</p>
<pre class="lang-yaml prettyprint-override"><code>- name: Get services info
  community.general.redfish_info:
    category: Manager
    command: GetNetworkProtocols
    baseuri: &quot;{{ baseuri }}&quot;
    username: &quot;{{ username }}&quot;
    password: &quot;{{ password }}&quot;
  register: result

- debug:
    var: result
</code></pre>
<p>you will get different NTP properties:</p>
<pre class="lang-yaml prettyprint-override"><code>...
NTPServers:
- 127.0.0.1
- 127.0.0.1
NTPServers@odata.count: 2
ProtocolEnabled: true
...
</code></pre>
<p>And this time it is a win for redfish_info as it turns out you have to use the properties from its output. Example:</p>
<pre class="lang-yaml prettyprint-override"><code>- name: Set NTP
  community.general.redfish_config:
    category: Manager
    command: SetNetworkProtocols
    network_protocols:
      NTPServers:
        - 127.0.0.1
        - 127.0.0.1
      ProtocolEnabled: true
    baseuri: &quot;{{ baseuri }}&quot;
    username: &quot;{{ username }}&quot;
    password: &quot;{{ password }}&quot;
</code></pre>
<h1>Further reading</h1>
<p>Besides the examples of the Ansible modules, you can get more examples here:</p>
<ul>
<li><a href="https://github.com/DMTF/Redfish-Ansible-Playbooks" rel="nofollow noreferrer">https://github.com/DMTF/Redfish-Ansible-Playbooks</a></li>
</ul>

CC BY-SA 4.0
2024-02-29T16:51:05.837Z
2024-03-01T07:21:16.873Z
2024-03-01T07:21:16.873Z
stackprotector
<p>I plan to configure Supermicro servers via the Redfish API. Ansible provides the following modules for the Redfish API:</p>
<ul>
<li><a href="https://docs.ansible.com/ansible/latest/collections/community/general/redfish_command_module.html" rel="nofollow noreferrer">community.general.redfish_command</a></li>
<li><a href="https://docs.ansible.com/ansible/latest/collections/community/general/redfish_config_module.html" rel="nofollow noreferrer">community.general.redfish_config</a></li>
</ul>
<p>Supermicro offers <a href="https://www.supermicro.com/manuals/other/RedfishRefGuide.pdf" rel="nofollow noreferrer">this</a> Redfish Reference Guide, which describes its Redfish REST API in detail. However, the Ansible modules use some sort of <em>commands</em> to do the configurations, instead of URIs.</p>
<p>Can someone explain how to map the API options to the Ansible modules? E. g., how can I use the Ansible modules to set the hostname or to provide NTP settings?</p>

<ansible>
Ansible - Configuring Supermicro servers via Redfish API
stackprotector
# Ansible - Configuring Supermicro servers via Redfish API

(Asked by: username_0 on 2022-11-17)

I plan to configure Supermicro servers via the Redfish API. Ansible provides the following modules for the Redfish API:

* [community.general.redfish\_command](https://docs.ansible.com/ansible/latest/collections/community/general/redfish_command_module.html)
* [community.general.redfish\_config](https://docs.ansible.com/ansible/latest/collections/community/general/redfish_config_module.html)

Supermicro offers [this](https://www.supermicro.com/manuals/other/RedfishRefGuide.pdf) Redfish Reference Guide, which describes its Redfish REST API in detail. However, the Ansible modules use some sort of *commands* to do the configurations, instead of URIs.

Can someone explain how to map the API options to the Ansible modules? E. g., how can I use the Ansible modules to set the hostname or to provide NTP settings?

**Tags:** ansible


---

## 2 answers

### Answer by username_0 on 2024-02-29. Score: 3 | Accepted answer

As outlined in username_1's helpful answer, you currently really have to dig down into the code to get working examples for Ansible's Redfish modules.
As a rule of thumb, I recommend to look at the info you can get, to get an idea of info you can probably set. Use both the Supermicro Redfish docs and the redfish_info module to see what you can get. Be aware, the results are not identical and neither the former nor the latter is more complete than the other. The two examples below will highlight some differences.
The "commands" used by the Ansible modules cannot be found in the Supermicro/Redfish docs. They are synonyms for certain API URIs. You have to look them up in the code, e. g. here and try to map them to the Supermicro/Redfish docs. Or dig down deeper to get to the functions that compose the URLs.
Hostname
From the Supermicro docs, you can see that there is a property called HostName:

URI: /redfish/v1/Managers/1/EthernetInterfaces/1
Method: GET
Response: 200
{
    ...
    "MTUSize": 1500,
    "HostName": "local",
    "FQDN": "local.supermicro.com",
    ...
}


FYI, querying the same info with Ansible, e. g.:
- name: Get nic info
  community.general.redfish_info:
    category: Manager
    command: GetManagerNicInventory
    baseuri: "{{ baseuri }}"
    username: "{{ username }}"
    password: "{{ password }}"
  register: result

- debug:
    var: result

will not return a "hostname" property (output omitted). So a win for the Supermicro docs...
Fortunately, you can still set the hostname with Ansible:
- name: Set hostname
  community.general.redfish_config:
    category: Manager
    command: SetManagerNic
    nic_config:
      HostName: MyHostname
    baseuri: "{{ baseuri }}"
    username: "{{ username }}"
    password: "{{ password }}"

NTP
The Supermicro docs show the following NTP properties:

URI: /redfish/v1/Managers/1/Oem/Supermicro/NTP
Method: PATCH
Payload:
{
    "NTPEnable": true,
    "PrimaryNTPServer":"127.0.0.1",
    "SecondaryNTPServer":"127.0.0.1",
    "DaylightSavingTime": false
}


But with the following Ansible tasks:
- name: Get services info
  community.general.redfish_info:
    category: Manager
    command: GetNetworkProtocols
    baseuri: "{{ baseuri }}"
    username: "{{ username }}"
    password: "{{ password }}"
  register: result

- debug:
    var: result

you will get different NTP properties:
...
NTPServers:
- 127.0.0.1
- 127.0.0.1
NTPServers@odata.count: 2
ProtocolEnabled: true
...

And this time it is a win for redfish_info as it turns out you have to use the properties from its output. Example:
- name: Set NTP
  community.general.redfish_config:
    category: Manager
    command: SetNetworkProtocols
    network_protocols:
      NTPServers:
        - 127.0.0.1
        - 127.0.0.1
      ProtocolEnabled: true
    baseuri: "{{ baseuri }}"
    username: "{{ username }}"
    password: "{{ password }}"

Further reading
Besides the examples of the Ansible modules, you can get more examples here:

https://github.com/DMTF/Redfish-Ansible-Playbooks


---

### Answer by username_1 on 2022-12-04. Score: 4

Supermicro offers this Redfish Reference Guide, which describes its Redfish REST API in detail.

Right. According the documentation you've referenced, Ch. 4 "Using RESTful APIs" p. 13 ff., the structure of the REST API call seems to be
https://${URL}/redfish/v1/${CATEGORY} ...

followed by further actions, commands, tasks or payloads.

Can someone explain how to map the API options to the Ansible modules?

After looking up the module documentation examples and the source code

plugins/modules/redfish_config.py
plugins/modules/redfish_command.py

it turns out that the modules using

plugins/module_utils/redfish_utils.py

as a wrapper the utilize the REST API. It maps the REST API structure to the parameter structure of the modules (category, command, payload). For a better understanding you may have a look into the mentioned source.

How can I use the Ansible modules to set the hostname or to provide NTP settings?

According the source it seems to be the manager_services for NTP. Because of the lack of the specific environment I'm not able to investigate this further and to do tests, therefore for how to use it you may also have a look into the source.
To get familar with the Redfish RESTful API you may also have a look into DMTF Redfishtool it

was originally written during the development of the Redfish specification to help find ambiguities in the spec.

Further Examples
There are some explanations and a general programming example from a bigger production environment available

Krenn Wiki Redfish

Documentation

Redfish User Guide


---

