AIX Open Source

 View Only
Expand all | Collapse all

Alt_disk_copy ansible playbook issue for AIX

  • 1.  Alt_disk_copy ansible playbook issue for AIX

    Posted Tue August 08, 2023 11:12 AM

    Hi Team,

    We are running playbook for alternate disk copy on AIX servers. So if we define the disk name it is working perfectly fine. But how we can use the same disk where we had clone previously. Because sometime disk number would be vary. So what option we should use in that playbook.

    ---
    - name: Alt_Disk in AIX
      hosts: "{{ hosts_val }}"
      gather_facts: no
      collections:
        - ibm.power_aix

      vars:
        hosts_val: all
        targets_val: hdisk1
      tasks:

        - name: Perform a cleanup of any existing alternate disk copy and old rootvg
          alt_disk:
            action: clean
            allow_old_rootvg: yes

        - name: Perform an alternate disk copy of the rootvg to hdisk1
          alt_disk:
            action: copy
            targets: "{{ targets_val }}"



    ------------------------------
    Manoj Kumar
    ------------------------------


  • 2.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Thu August 10, 2023 08:28 AM

    Hi Team,

    Would you please check the above query and respond on it?



    ------------------------------
    Manoj Kumar
    ------------------------------



  • 3.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Fri August 11, 2023 08:20 AM

    Hi Manoj !

    In the "vars" section of the playbook which currently looks like this:

    vars:
        hosts_val: all
        targets_val: hdisk1

    You can add as many variables as you want and later use it in your tasks. Something like this:

    vars:
        hosts_val: all
        targets_val: hdisk1

        alt_target_val: hdisk2

    It could be any name. This is just an example.

    If you have any query regarding AIX ansible/vios collection, you can raise an issue here: https://github.com/IBM/ansible-power-aix/issues

    Thanks,

    Nitish



    ------------------------------
    Nitish Mishra
    ------------------------------



  • 4.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Fri August 11, 2023 10:09 AM

    Thanks Nitish. Actually I just wanted to know if we have bulk servers and we already have clone disk available so we just wanted to remove existing clone on each servers and create new one on same disk. In that case this playbook is not going to work as we have to put lot of variable. I will also raise this issue on the link you suggested.



    ------------------------------
    Manoj Kumar
    ------------------------------



  • 5.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Wed August 16, 2023 09:18 AM

    Hi Team,

    Did anyone check the above query? It would be really helpful.



    ------------------------------
    Manoj Kumar
    ------------------------------



  • 6.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Thu August 24, 2023 09:55 AM

    Hi Manoj,

    You can try use this perfectible ansible code I wrote :

      # Retrieve disk list
      - name: Retrieve disk list with lspv command
        ansible.builtin.shell:
          cmd: "lspv"
        register: pv_list
      
      # Create sysalt on existing altinst_rootvg or old_rootvg disk  
      - name: Create sysalt on existing altinst_rootvg or old_rootvg disk
        ibm.power_aix.alt_disk:
          action: copy
          force: True
          allow_old_rootvg: True
          targets: "{{ lspv_disk[0] }}"
        vars:
          lspv_disk: "{{ item|split() }}"
        with_list: "{{ pv_list.stdout_lines }}"
        when: '"_rootvg" in lspv_disk[2]'

    It retrieve pv list with lspv command. It would be better to use facts, but there are no facts that provide pv informations for alt_disk because it is not varyon...

    And for each pv line (from lspv), if the vgname is like "_rootvg" I force an alt_disk_copy even if it is an old_rootvg.

    I have to perfect the code to exit after the first clone (if there is multiple clone), anb failed if no alt_disk have been found.

    This code won't work too, if rootvg is mirrored.

    Please say me if it helps you.

    Regards.



    ------------------------------
    Damien LEMAGNEN
    AIX System Engineer/Architect
    NETIXWARE
    ------------------------------



  • 7.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Fri August 25, 2023 08:44 AM

    Hello Damien

    Thanks for sharing this. I am getting the following error. Please check the playbook which I have created and see if I am missing something.

    Error:

    TASK [Create sysalt on existing altinst_rootvg or old_rootvg disk] **************************************************************************************************************************************************************************
    fatal: [host]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: {{ item|split() }}: Unable to look up a name or access an attribute in template string ({{ item|split() }}).\nMake sure your variable name does not contain invalid characters like '-': descriptor 'split' for 'str' objects doesn't apply to a 'AnsibleUndefined' object. descriptor 'split' for 'str' objects doesn't apply to a 'AnsibleUndefined' object. Unable to look up a name or access an attribute in template string ({{ item|split() }}).\nMake sure your variable name does not contain invalid characters like '-': descriptor 'split' for 'str' objects doesn't apply to a 'AnsibleUndefined' object. descriptor 'split' for 'str' objects doesn't apply to a 'AnsibleUndefined' object. {{ item|split() }}: Unable to look up a name or access an attribute in template string ({{ item|split() }}).\nMake sure your variable name does not contain invalid characters like '-': descriptor 'split' for 'str' objects doesn't apply to a 'AnsibleUndefined' object. descriptor 'split' for 'str' objects doesn't apply to a 'AnsibleUndefined' object. Unable to look up a name or access an attribute in template string ({{ item|split() }}).\nMake sure your variable name does not contain invalid characters like '-': descriptor 'split' for 'str' objects doesn't apply to a 'AnsibleUndefined' object. descriptor 'split' for 'str' objects doesn't apply to a 'AnsibleUndefined' object\n\nThe error appears to be in '/home/automation/ansible/AIX/alt_disk_copy.yml': line 15, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n    # Create sysalt on existing altinst_rootvg or old_rootvg disk\n    - name: Create sysalt on existing altinst_rootvg or old_rootvg disk\n      ^ here\n"}

    My Playbook
    ---
    - name: Alt_Disk in AIX
      hosts: host
      gather_facts: no
     
      tasks:
     
        # Retrieve disk list
        - name: Retrieve disk list with lspv command
          ansible.builtin.shell:
            cmd: "lspv"
          register: pv_list
     
        # Create sysalt on existing altinst_rootvg or old_rootvg disk
        - name: Create sysalt on existing altinst_rootvg or old_rootvg disk
          ibm.power_aix.alt_disk:
            action: copy
            force: True
            allow_old_rootvg: True
            targets: "{{ lspv_disk[0] }}"
     
      vars:
        lspv_disk: "{{ item|split() }}"
        with_list: "{{ pv_list.stdout_lines }}"
        when: '"_rootvg" in lspv_disk[2]'



    ------------------------------
    Manoj Kumar
    ------------------------------



  • 8.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Fri August 25, 2023 09:32 AM

    Hello Manoj,

    At the end, the vars paragraph must be a part of previous task.

    Please use directly the yml file I upload.

    Regards.



    ------------------------------
    Damien LEMAGNEN
    AIX System Engineer/Architect
    NETIXWARE
    ------------------------------



  • 9.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Fri August 25, 2023 09:38 AM
    Edited by Damien LEMAGNEN Fri August 25, 2023 09:40 AM

    Please copy and respect spaces and blank lines.

    Replace "{{ my_host }}" by what you want

    ---
    - name: Template for AIX playbooks
      hosts: "{{ my_host }}"
      strategy: linear
      gather_facts: false
      
      
      # Tasks
      tasks:
      
      # Retrieve disk list
      - name: Retrieve disk list with lspv command
        ansible.builtin.shell:
          cmd: "lspv"
        register: pv_list
      
      # Create sysalt on existing altinst_rootvg or old_rootvg disk  
      - name: Create sysalt on existing altinst_rootvg or old_rootvg disk
        ibm.power_aix.alt_disk:
          action: copy
          force: True
          allow_old_rootvg: True
          targets: "{{ lspv_disk[0] }}"
        register: sysalt_run
        when: '"_rootvg" in lspv_disk[2]'
        vars:
          lspv_disk: "{{ item|split() }}"
        with_list: "{{ pv_list.stdout_lines }}"
      
      # Fail if no sysalt processed  
      - name: Fail if no sysalt processed
        ansible.builtin.fail:
          msg: No sysalt have been processed
        when: sysalt_run.changed == false
    



    ------------------------------
    Damien LEMAGNEN
    AIX System Engineer/Architect
    NETIXWARE
    ------------------------------



  • 10.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Fri August 25, 2023 11:18 AM

    Thanks Damien, the playbook which you shared above is working fine and also the playbook which you shared earlier after making some changes in indentation  and we are able to take the clone on the server, however we tested this on one server which is having total 3 disk. But while creating sysalt it is scanning all disk like I given below output. But if a server having more than 100 disk, will it show all 100 disk in ansible logs? We have to create clone across more than 300 servers so in that case it will generate lot of logs. Is there any option available so that only altinst_rootvg or old_rootvg would be read.

    PLAY [Template for AIX playbooks] ***********************************************************************************************************************************************************************************************************
     
    TASK [Retrieve disk list with lspv command] *************************************************************************************************************************************************************************************************
    changed: [host]
     
    TASK [Create sysalt on existing altinst_rootvg or old_rootvg disk] **************************************************************************************************************************************************************************
    skipping: [host] => (item=hdisk3          00f84014c5ab287b                    rootvg          active      )
    changed: [host] => (item=hdisk4          00f84014c9e430b8                    altinst_rootvg              )
    skipping: [host] => (item=hdisk5          00f840145032f877                    vg01            active      )
     
    TASK [Fail if no sysalt processed] **********************************************************************************************************************************************************************************************************
    skipping: [host]
     
    PLAY RECAP **********************************************************************************************************************************************************************************************************************************
    host: ok=2    changed=2    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0



    ------------------------------
    Manoj Kumar
    ------------------------------



  • 11.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Sat August 26, 2023 08:06 AM

    Thanks for trying this playbook.

    I agree with you, if there are to much disks on the host, the task log can bee very long If you want to easily known wich disk have been used for the alt_disk.

    The easiest way is to modify the command in shell task to put something like :

    lspv | grep -E "_rootvg" | grep -v grep

    But for me the PLAY RECAP is suffisant to know if a sys_alt have been created on each host.

    Regards,



    ------------------------------
    Damien LEMAGNEN
    AIX System Engineer/Architect
    NETIXWARE
    ------------------------------



  • 12.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Mon August 28, 2023 11:31 AM

    Hi Damien,

    I try to update the command but getting below error once try to run playbook. Do we have any idea on this?

    ansible-playbook alt_disk_copy.yml -check

    PLAY [Alt Disk copy in AIX] ********************************************************************************************************************************************

    TASK [Retrieve disk list with lspv command] ****************************************************************************************************************************
    fatal: [host]: FAILED! => {"msg": "the connection plugin 'heck' was not found"}

    PLAY RECAP *************************************************************************************************************************************************************
    host: ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

    Now playbook look like this.

    ---
    - name: Alt Disk copy in AIX
      hosts: all
      strategy: linear
      gather_facts: false


      # Tasks
      tasks:

      # Retrieve disk list
      - name: Retrieve disk list with lspv command
        ansible.builtin.shell:
          cmd: 'lspv | grep -i "_rootvg"|grep -v grep'
        register: pv_list

      # Create sysalt on existing altinst_rootvg or old_rootvg disk
      - name: Create sysalt on existing altinst_rootvg or old_rootvg disk
        ibm.power_aix.alt_disk:
          action: copy
          force: True
          allow_old_rootvg: True
          targets: "{{ lspv_disk[0] }}"
        register: sysalt_run
        when: '"_rootvg" in lspv_disk[2]'
        vars:
          lspv_disk: "{{ item|split() }}"
        with_list: "{{ pv_list.stdout_lines }}"

      # Fail if no sysalt processed
      - name: Fail if no sysalt processed
        ansible.builtin.fail:
          msg: No sysalt have been processed
        when: sysalt_run.changed == false



    ------------------------------
    Manoj Kumar
    ------------------------------



  • 13.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Mon August 28, 2023 11:37 AM

    Sorry Damien, please ignore the previous query on playbook is not working. Actually I was running wrong command. It must be --check rather than -check.

    I will keep you posted for the result. Apologies for the inconvenience.



    ------------------------------
    Manoj Kumar
    ------------------------------



  • 14.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Mon August 28, 2023 12:14 PM

    Thanks Damien for all your help, playbook working fine as expected. Really appreciate for the help.



    ------------------------------
    Manoj Kumar
    ------------------------------



  • 15.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Fri August 25, 2023 10:58 AM
    It may just be the email messing up the indentation, but it looks incorrect.

    I think you've created three variables named lspv_disk, with_list, and when. So there is no loop, so {{ item }} is not defined.

    Fix the indentation on the with_list and when, and you'll be much closer. :)

    -- 
    Stephen L. Ulmer
    Enterprise Architect
    Mainline Information Systems
    (m) 352-870-8649










  • 16.  RE: Alt_disk_copy ansible playbook issue for AIX

    Posted Mon August 28, 2023 11:28 AM

    Thanks Stephen.



    ------------------------------
    Manoj Kumar
    ------------------------------