Automation with Power

 View Only

CREATE A CMDB FOR IBM POWER ENVIROMENT USING ANSIBLE – PART 1

By Nicolae Chirea posted Fri August 25, 2023 06:44 AM

  

CREATE A CMDB FOR IBM POWER ENVIROMENT USING ANSIBLE – PART 1

The initial step in automating the management of IBM Power architecture is to establish a comprehensive inventory of its components. This inventory should be both accurate and up-to-date, and naturally, it should be managed by Ansible. If you already have a configuration management database (CMDB) this can be a method to maintain it or, if you don’t have one yet, it could be your first step to get one. 

For its characteristics (ease of use, portability, small footprint, etc) I chose SQLite3. Above that there are 2 more reasons:


First steps are: create the database directory and add the first table:

- name: configuration db and tables creation

  hosts: myhost

  gather_facts: False

  tasks:

  - name: create database directory

    file:

      path: /home/ansible/db1

      state: directory

      mode: '0777'

  - name: Create lpar table

    ibm.power_ibmi.ibmi_sqlite3:

      database: "/home/ansible/db1/config.db"

      sql: "CREATE TABLE IF NOT EXISTS lpar  

           (NOMBRELPAR CHAR(60) NOT NULL,

            NOMBRESYS CHAR(40) NOT NULL,

            IPHMC CHAR(15) NOT NULL,

            TIPOLPAR CHAR(10),

            OSVERSION CHAR(80),

            STATE CHAR(20),

            UNIQUE(NOMBRELPAR,NOMBRESYS) )"

As you can see SQL syntax is quite straightforward. When I need a new table I just add corresponding task to this playbook. In order to run it anytime I used clause “IF NOT EXISTS “  - my way to achieve idempotence here. Once table is created I need to retrieve configuration data from HMC. The ansible collection ibm.power_hmc provide necessary module to access and control HMC.

I begin by getting a list off Power systems managed by  HMC:

- name: Retrieve Power hosts from HMC

  ibm.power_hmc.hmc_command:

    hmc_host: "{{ hmc_ip }}"

    hmc_auth:

         username: '{{ usuario }}'

         password: '{{ pass_hmc }}'

    cmd:  lssyscfg -r sys -F name,state

  register: info_sys

Observe that I only retrieve 2 parameters: name and state. If you want a more comprehensive database you could retrieve all parameters.

The info_sys variable has this content:

{

  "info_sys": {

    "changed": true,

    "command_output": [

      "SystemA,Operating",

      "SystemB,Operating"

    ],

Now that I have system names I can retrieve LPAR properties:

- name: Retrive lpar by system

  include_tasks: get_lpar.yml

  loop: "{{info_sys.command_output}}"

  when: sys_name.split(',')[1]=="Operating"

  loop_control:

    loop_var: sys_name

So I do a loop on command_output (see infos:sys variable) and as I want to do various task by each system I put them in another playbook: get_lpar.yml. And information is retrieved only if the system is Operating – the position 1 in info_sys.command_output. The info_sys.command_output variable is passed to included tasks as sys_name. 

What do I have in get_lpar.yml? First off all, retrieve lpar properties:

- name: Retrieve lpar properties

  ibm.power_hmc.hmc_command:

    hmc_host: "{{ hmc_ip }}"

    hmc_auth:

         username: '{{ usuario }}'

         password: '{{ pass_hmc }}'

    cmd:  lssyscfg -r lpar -m "{{sys_name.split(',')[0]}}"  -F name,lpar_env,os_version, state

  register: info_lpar

Observe that managed system is position 0 in sys_name variable.

The content of info_lpar variable:

{

  "changed": true,

  "command_output": [

    "V7R4B_DR,os400,Desconocido,Not Activated",

    "ocpworker1-5cbf9fe7-00000030,aixlinux,Desconocido,Running",

    "VIOS1,vioserver,VIOS 3.1.4.21,Running"

  ],

Next step is inserting retrieved values into SQLite table:

- name: Insert values in lpar table

  ibm.power_ibmi.ibmi_sqlite3:

    database: "/home/ansible/db1/config.db"

    sql: INSERT INTO  lpar (NOMBRELPAR,NOMBRESYS,IPHMC,TIPOLPAR,OSVERSION, STATE)

           VALUES ("{{item.split(',')[0]}}","{{sys_name.split(',')[0]}}","{{hmc_ip}}","{{item.split(',')[1]}}", "{{item.split(',')[2]}}", "{{item.split(',')[3]}}")

  loop: "{{info_lpar.command_output}}"

This insertion method is quite slow. In the second part of this blog, I will address a more efficient approach.

Finally I can view the table through sqlite-web:

The idea is to execute this process every night. As can be observed, creating a CMDB with IBM Power details is not overly complex. By utilizing dedicated modules for IBMi, AIX, and Linux, the CMDB can be enriched with operating system data and installed software information.

#IBMChampion
0 comments
69 views

Permalink