AIX Open Source

AIX Open Source

Share your experiences and connect with fellow developers to discover how to build and manage open source software for the AIX operating system

 View Only
  • 1.  Ansible playbook to validate HBA connectivity

    Posted Tue November 07, 2023 10:21 AM

    I'm fairly new to Ansible and have been looking for a way to use it to help validate all my fcs devices are connected to the fabric.  So in looking at community.general.aix_devices and ibm.power_aix.devices I can see ways to rmdev, mkdev and change attributes, but what I'm hoping for, is a playbook that for each fcs device, validates it's connected to the fabric (fcstat) and if not, run a rmdev and mkdev on it.

    Anyone have any pointers on where I can find something like that, that I can work off of?



    ------------------------------
    Mark Steele
    ------------------------------


  • 2.  RE: Ansible playbook to validate HBA connectivity

    Posted Tue November 07, 2023 11:07 AM

    I think we have to split this into smaller steps. First we have to gather data with the "setup" module or "gather_facts: true" in your playbook and maybe add some AIX specific data with the module "ibm.power_aix.mpio". When we have all the data we are able to automate the further steps with "ibm.power_aix.devices" when some fc-adapter is missing in your environment.

    Just a small piece of code to give you an example of how to gather all the data you maybe need to evaluate the system state:

    - hosts: all
      gather_facts: true
      become: true
      tasks:
        - name: Gather mpio data
          ibm.power_aix.mpio:
    
        - name: Show all the ansible facts
          debug:
            var: ansible_facts
    
    ... some checks and maybe re-creation by using ibm.power_aix.devices ...


    ------------------------------
    Niklas
    System Engineer UNIX and Linux on Power
    ------------------------------



  • 3.  RE: Ansible playbook to validate HBA connectivity

    Posted Wed November 08, 2023 10:14 AM

    Thanks Niklas, however, the mpio module shows me information about disks paths, not the state of the HBA and if it's connected. Maybe I should clarify. This playbook would be run on a newly deployed system to help validate all the cabling is completed and shows connectivity. So simply, if the fcstat command returns anything, we are likely connected and if it errors out, we are not. Not sure if I've found a different command that will show link status.

    ok: [aixtest01] => {
        "ansible_facts.mpio": {
            "drivers": {
                "2107DS8K": {
                    "option": "NO_OVERRIDE",
                    "options": [
                        "NO_OVERRIDE",
                        "AIX_AAPCM",
                        "AIX_non_MPIO"
       ...
            "paths": {
                "hdisk0": {
                    "fscsi0": {
                        "5005076810115357,0": {
                            "path_id": 1,
                            "path_status": "Available",
                            "status": "Enabled"
                        },
                        "500507681011536e,0": {
                            "path_id": 0,
                            "path_status": "Available",
                            "status": "Enabled"
                        }
                    },
       ...



    ------------------------------
    Mark Steele
    ------------------------------



  • 4.  RE: Ansible playbook to validate HBA connectivity

    Posted Thu November 09, 2023 03:36 AM

    I think this is not covered by any existing AIX module and "ansible.builtin.shell" will help to execute your well-known AIX commands.

        - name: Gather fcstat data
          ansible.builtin.shell: fcstat fcs0
          changed_when: false
          register: fcstat_data
    
        - debug:
            var: fcstat_data

    You can place any idea for new modules here as "Issue": GitHub - IBM/ansible-power-aix: Developer contributions for Ansible Automation on Power



    ------------------------------
    Niklas
    System Engineer UNIX and Linux on Power
    ------------------------------



  • 5.  RE: Ansible playbook to validate HBA connectivity

    Posted Thu November 16, 2023 06:14 PM
    For something like this, I think you want ansible.builtin.command instead. The best practice is to only use ansible.builtin.shell is you are actually using shell redirects, etc.

    -- 
    Stephen L. Ulmer
    Enterprise Architect
    Mainline Information Systems






  • 6.  RE: Ansible playbook to validate HBA connectivity

    Posted Wed November 08, 2023 10:01 AM

    rmdev+mkdev is an overkill, but cfgmgr should be enough.



    ------------------------------
    José Pina Coelho
    IT Specialist at Kyndryl
    ------------------------------



  • 7.  RE: Ansible playbook to validate HBA connectivity

    Posted Thu November 09, 2023 04:11 AM

    Hi Mark,

    I agree with José - I don't think rmdev/mkdev is what you want. If you don't want to wait for cfgmgr, you can run it with just one device and it will search for all child devices of it.

    But as a starting point:

    ---
    - name: Test FC HBA and fail if it is not connected
      hosts: all
      become: true
      gather_facts: false
      
      tasks:
        - name: Get devices information
          ansible.builtin.setup:
            gather_subset: 
              - devices
        - name: Get fscsi devices
          ansible.builtin.set_fact:
            fscsi_dev: "{{ ansible_facts.devices | ansible.builtin.dict2items | community.general.json_query(q) }}"
          vars:
            q: "[?contains(value.type, 'FC SCSI I/O Controller Protocol Device')].{ name: key, attach: value.attributes.attach, scsi_id: value.attributes.scsi_id }"
        - name: Get parents for fscsi devices
          ansible.builtin.command:
            cmd: "lsdev -l {{ item.name }} -F parent"
          register: parent_output
          loop: "{{ fscsi_dev }}"
          loop_control:
            label: "Getting parent device of {{ item.name }}"
          changed_when: false
        - name: Joining information
          ansible.builtin.set_fact:
            fscsi: "{{ fscsi | default([]) + [{ 'name': item.name, 'attach': item.attach, 'scsi_id': item.scsi_id, 'parent': parent_output.results[idx].stdout }] }}"
          loop: "{{ fscsi_dev }}"
          loop_control:
            label: "Adding parent device to {{ item.name }}"
            index_var: idx
        - name: Removing devices if scsi_id is undefined or attach is not switch
          ansible.builtin.command:
            cmd: "rmdev -Rl {{ item.parent }}"
          loop: "{{ fscsi }}"
          loop_control:
            label: "Removing {{ item.parent }}"
          when: item.attach != 'switch' or item.scsi_id == ''
        - name: Recreating removed devices
          ansible.builtin.command:
            cmd: "cfgmgr -l {{ item.parent }}"
          loop: "{{ fscsi }}"
          loop_control:
            label: "Recreating {{ item.parent }}"
          when: item.attach != 'switch' or item.scsi_id == ''
        - name: Re-gather devices information
          ansible.builtin.setup:
            gather_subset: 
              - devices
        - name: Re-get fscsi devices
          ansible.builtin.set_fact:
            fscsi_dev: "{{ ansible_facts.devices | ansible.builtin.dict2items | community.general.json_query(q) }}"
          vars:
            q: "[?contains(value.type, 'FC SCSI I/O Controller Protocol Device')].{ name: key, attach: value.attributes.attach, scsi_id: value.attributes.scsi_id }"
        - name: Fail if there are still devices without connection
          ansible.builtin.fail:
            msg: "The device {{ item.name }} has wrong value for attach ({{ item.attach }}) or scsi_id ({{ item.scsi_id }})"
          loop: "{{ fscsi_dev }}"
          loop_control:
            label: "Checking {{ item.name }}"
          when: item.attach != 'switch' or item.scsi_id == ''
    



    ------------------------------
    Andrey Klyachkin

    https://www.power-devops.com
    ------------------------------



  • 8.  RE: Ansible playbook to validate HBA connectivity

    Posted Thu November 09, 2023 03:17 PM

    Thank you so very much Andrey, this will give me plenty to chew through and is an excellent tool for my learning, very much appreciated. For what I'm looking to achieve, this is spot on. One caveat I found, is that this would not discover a once connected connection that has become disconnected since funning cfgmgr. Since it's getting its connection status from the ODM. Again, great for my purposes. Thanks!

    Jose, complete legit point of using cfgmgr -l, thanks. 



    ------------------------------
    Mark Steele
    ------------------------------