community.general.imc_rest (8.5.0) — module

Manage Cisco IMC hardware through its REST API

Authors: Dag Wieers (@dagwieers)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Provides direct access to the Cisco IMC REST API.

Perform any configuration changes and actions that the Cisco IMC supports.

More information about the IMC REST API is available from U(http://www.cisco.com/c/en/us/td/docs/unified_computing/ucs/c/sw/api/3_0/b_Cisco_IMC_api_301.html).


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Power down server
  community.general.imc_rest:
    hostname: '{{ imc_hostname }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: false  # only do this when you trust the network!
    content: |
      <configConfMo><inConfig>
        <computeRackUnit dn="sys/rack-unit-1" adminPower="down"/>
      </inConfig></configConfMo>
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Configure IMC using multiple XML fragments
  community.general.imc_rest:
    hostname: '{{ imc_hostname }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: false  # only do this when you trust the network!
    timeout: 120
    content: |
      <!-- Configure Serial-on-LAN -->
      <configConfMo><inConfig>
        <solIf dn="sys/rack-unit-1/sol-if" adminState="enable" speed=="115200" comport="com0"/>
      </inConfig></configConfMo>

      <!-- Configure Console Redirection -->
      <configConfMo><inConfig>
        <biosVfConsoleRedirection dn="sys/rack-unit-1/bios/bios-settings/Console-redirection"
          vpBaudRate="115200"
          vpConsoleRedirection="com-0"
          vpFlowControl="none"
          vpTerminalType="vt100"
          vpPuttyKeyPad="LINUX"
          vpRedirectionAfterPOST="Always Enable"/>
      </inConfig></configConfMo>
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Enable PXE boot and power-cycle server
  community.general.imc_rest:
    hostname: '{{ imc_hostname }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: false  # only do this when you trust the network!
    content: |
      <!-- Configure PXE boot -->
      <configConfMo><inConfig>
        <lsbootLan dn="sys/rack-unit-1/boot-policy/lan-read-only" access="read-only" order="1" prot="pxe" type="lan"/>
      </inConfig></configConfMo>

      <!-- Power cycle server -->
      <configConfMo><inConfig>
        <computeRackUnit dn="sys/rack-unit-1" adminPower="cycle-immediate"/>
      </inConfig></configConfMo>
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reconfigure IMC to boot from storage
  community.general.imc_rest:
    hostname: '{{ imc_host }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: false  # only do this when you trust the network!
    content: |
      <configConfMo><inConfig>
        <lsbootStorage dn="sys/rack-unit-1/boot-policy/storage-read-write" access="read-write" order="1" type="storage"/>
      </inConfig></configConfMo>
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add customer description to server
  community.general.imc_rest:
    hostname: '{{ imc_host }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: false  # only do this when you trust the network!
    content: |
        <configConfMo><inConfig>
          <computeRackUnit dn="sys/rack-unit-1" usrLbl="Customer Lab - POD{{ pod_id }} - {{ inventory_hostname_short }}"/>
        </inConfig></configConfMo>
    delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Disable HTTP and increase session timeout to max value 10800 secs
  community.general.imc_rest:
    hostname: '{{ imc_host }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: false  # only do this when you trust the network!
    timeout: 120
    content: |
        <configConfMo><inConfig>
          <commHttp dn="sys/svc-ext/http-svc" adminState="disabled"/>
        </inConfig></configConfMo>

        <configConfMo><inConfig>
          <commHttps dn="sys/svc-ext/https-svc" adminState="enabled" sessionTimeout="10800"/>
        </inConfig></configConfMo>
    delegate_to: localhost

Inputs

    
path:
    aliases:
    - src
    - config_file
    description:
    - Name of the absolute path of the filename that includes the body of the http request
      being sent to the Cisco IMC REST API.
    - Parameter O(path) is mutual exclusive with parameter O(content).
    type: path

content:
    description:
    - When used instead of O(path), sets the content of the API requests directly.
    - This may be convenient to template simple requests, for anything complex use the
      M(ansible.builtin.template) module.
    - You can collate multiple IMC XML fragments and they will be processed sequentially
      in a single stream, the Cisco IMC output is subsequently merged.
    - Parameter O(content) is mutual exclusive with parameter O(path).
    type: str

timeout:
    default: 60
    description:
    - The socket level timeout in seconds.
    - This is the time that every single connection (every fragment) can spend. If this
      O(timeout) is reached, the module will fail with a C(Connection failure) indicating
      that C(The read operation timed out).
    type: int

hostname:
    aliases:
    - host
    - ip
    description:
    - IP Address or hostname of Cisco IMC, resolvable by Ansible control host.
    required: true
    type: str

password:
    default: password
    description:
    - The password to use for authentication.
    type: str

protocol:
    choices:
    - http
    - https
    default: https
    description:
    - Connection protocol to use.
    type: str

username:
    aliases:
    - user
    default: admin
    description:
    - Username used to login to the switch.
    type: str

validate_certs:
    default: true
    description:
    - If V(false), SSL certificates will not be validated.
    - This should only set to V(false) used on personally controlled sites using self-signed
      certificates.
    type: bool

Outputs

aaLogin:
  description: Cisco IMC XML output for the login, translated to JSON using Cobra
    convention
  returned: success
  sample: "\"attributes\": {\n    \"cookie\": \"\",\n    \"outCookie\": \"1498902428/9de6dc36-417c-157c-106c-139efe2dc02a\"\
    ,\n    \"outPriv\": \"admin\",\n    \"outRefreshPeriod\": \"600\",\n    \"outSessionId\"\
    : \"114\",\n    \"outVersion\": \"2.0(13e)\",\n    \"response\": \"yes\"\n}\n"
  type: dict
configConfMo:
  description: Cisco IMC XML output for any configConfMo XML fragments, translated
    to JSON using Cobra convention
  returned: success
  sample: ''
  type: dict
elapsed:
  description: Elapsed time in seconds
  returned: always
  sample: 31
  type: int
error:
  description: Cisco IMC XML error output for last request, translated to JSON using
    Cobra convention
  returned: failed
  sample: "\"attributes\": {\n    \"cookie\": \"\",\n    \"errorCode\": \"ERR-xml-parse-error\"\
    ,\n    \"errorDescr\": \"XML PARSING ERROR: Element 'computeRackUnit', attribute\
    \ 'admin_Power': The attribute 'admin_Power' is not allowed. \",\n    \"invocationResult\"\
    : \"594\",\n    \"response\": \"yes\"\n}\n"
  type: dict
error_code:
  description: Cisco IMC error code
  returned: failed
  sample: ERR-xml-parse-error
  type: str
error_text:
  description: Cisco IMC error message
  returned: failed
  sample: 'XML PARSING ERROR: Element ''computeRackUnit'', attribute ''admin_Power'':
    The attribute ''admin_Power'' is not allowed.

    '
  type: str
input:
  description: RAW XML input sent to the Cisco IMC, causing the error
  returned: failed
  sample: '<configConfMo><inConfig><computeRackUnit dn="sys/rack-unit-1" admin_Power="down"/></inConfig></configConfMo>

    '
  type: str
output:
  description: RAW XML output received from the Cisco IMC, with error details
  returned: failed
  sample: "<error cookie=\"\"\n  response=\"yes\"\n  errorCode=\"ERR-xml-parse-error\"\
    \n  invocationResult=\"594\"\n  errorDescr=\"XML PARSING ERROR: Element 'computeRackUnit',\
    \ attribute 'admin_Power': The attribute 'admin_Power' is not allowed.\\n\"/>\n"
  type: str
response:
  description: HTTP response message, including content length
  returned: always
  sample: OK (729 bytes)
  type: str
status:
  description: The HTTP response status code
  returned: always
  sample: 200
  type: dict