ansible.builtin.imc_rest (v2.9.27) — module

Manage Cisco IMC hardware through its REST API

| "added in version" 2.4 of ansible.builtin"

Authors: Dag Wieers (@dagwieers)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.9.27

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
  imc_rest:
    hostname: '{{ imc_hostname }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    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
  imc_rest:
    hostname: '{{ imc_hostname }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    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
  imc_rest:
    hostname: '{{ imc_hostname }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    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
  imc_rest:
    hostname: '{{ imc_host }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    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
  imc_rest:
    hostname: '{{ imc_host }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    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
  imc_rest:
    hostname: '{{ imc_host }}'
    username: '{{ imc_username }}'
    password: '{{ imc_password }}'
    validate_certs: no
    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 C(path) is mutual exclusive with parameter C(content).

content:
    description:
    - When used instead of C(path), sets the content of the API requests directly.
    - This may be convenient to template simple requests, for anything complex use the
      M(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 C(content) is mutual exclusive with parameter C(path).

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

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

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

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

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

validate_certs:
    default: 'yes'
    description:
    - If C(no), SSL certificates will not be validated.
    - This should only set to C(no) 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