IBM / ansible-power-aix

Developer contributions for Ansible Automation on Power
https://ibm.github.io/ansible-power-aix/
GNU General Public License v3.0
80 stars 93 forks source link

Ansilbe throws errors: "The conditional check 'nimadm_phases_to_run is regex(\"[^0-9,]\") or nimadm_phases_to_run[-1] == ',''" while run playbook to updating AIX 7.3 Service pack. #526

Closed SpringIBM closed 1 month ago

SpringIBM commented 1 month ago

Describe the bug Run playbook and errors. [ckansible@efsnim-p1:/home/ckansible/ck-ans-02]$ ansible-playbook playbooks/cg_nim_alt_disk_migration_lpar112_hdisk0.yml -u root --private-key=./devops_key/devops_id_ed25519

PLAY [CK-PB - NIMADM playbook - Upgrading SP on AIX 7.3 TL02 SP00 to 7300-02-01-2346 with nimadm and Ansible] *************************************************************************

TASK [include_role : nim_alt_disk_migration] ******************************************************************************************************************************************

TASK [ibm.power_aix.nim_alt_disk_migration : Validating arguments against arg spec 'main' - This role is used to migrate a client OS levels from AIX 7.1/7.2 to AIX 7.3.] *************
ok: [lpar112 -> efsnim-p1]

TASK [ibm.power_aix.nim_alt_disk_migration : Fail if a NIM LPP resource is not specified] *********************************************************************************************
skipping: [lpar112]

TASK [ibm.power_aix.nim_alt_disk_migration : debug] ***********************************************************************************************************************************
ok: [lpar112 -> efsnim-p1] => {
    "msg": "LPP resource lpp_source_aix73 specified for migration"
}

TASK [ibm.power_aix.nim_alt_disk_migration : Check if CacheVG 'nimvg' exists] *********************************************************************************************************
ok: [lpar112 -> efsnim-p1]

TASK [ibm.power_aix.nim_alt_disk_migration : Fail when '{{ nimadm_phases_to_run }}' contains invalid characters] **********************************************************************
fatal: [lpar112 -> efsnim-p1]: FAILED! => {"msg": "The conditional check 'nimadm_phases_to_run is regex(\"[^0-9,]\") or nimadm_phases_to_run[-1] == ','' failed. The error was: error while evaluating conditional (nimadm_phases_to_run is regex(\"[^0-9,]\") or nimadm_phases_to_run[-1] == ','): 'nimadm_phases_to_run' is undefined. 'nimadm_phases_to_run' is undefined\n\nThe error appears to be in '/home/ckansible/ck-ans-02/ibmcollections/ansible_collections/ibm/power_aix/roles/nim_alt_disk_migration/tasks/main.yml': line 20, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: \"Fail when '{{ nimadm_phases_to_run }}' contains invalid characters\"\n  ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}

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

[ckansible@efsnim-p1:/home/ckansible/ck-ans-02]$

To Reproduce Steps to reproduce the behavior: ENV:

NIM LPP_SOURCE, SPOT, NIM client and lspv on nimclinent information.

root@efsnim-p1:/root> lsnim -l -l lpp_source_aix73
lpp_source_aix73:
   class        = resources
   type         = lpp_source
   arch         = power
   Rstate       = ready for use
   prev_state   = unavailable for use
   location     = /export/lpp_source/lpp_source_aix73
   simages      = yes
   alloc_count  = 0
   server       = master
   date_updated = Fri Apr 12 02:47:12 2024

root@efsnim-p1:/root> lsnim -l -l spot_aix73
spot_aix73:
   class         = resources
   type          = spot
   plat_defined  = chrp
   arch          = power
   bos_license   = yes
   Rstate        = ready for use
   prev_state    = verification is being performed
   location      = /export/spot/spot_aix73/usr
   version       = 7
   release       = 3
   mod           = 2
   oslevel_r     = 7300-02
   oslevel_s     = 7300-02-01-2346
   alloc_count   = 0
   server        = master
   if_supported  = chrp.64 ent
   Rstate_result = success
   date_updated  = Fri Apr 12 02:56:59 2024

root@efsnim-p1:/root> lsnim -l -l lpar112
lpar112:
   class           = machines
   type            = standalone
   installed_image = efsesb-ap1-p1_20240411_mksysb
   connect         = nimsh
   platform        = chrp
   netboot_kernel  = 64
   if1             = network1 lpar112 0
   cable_type1     = N/A
   Cstate          = ready for a NIM operation
   prev_state      = currently running
   Mstate          = not running
   cpuid           = 00C117E04B00
   Cstate_result   = success

root@efsnim-p1:/root> lspv
hdisk0          00c117e0c533bd6e                    rootvg          active
hdisk1          00c117e0cea7a3c0                    nimvg           active
root@efsnim-p1:/root> lsvg -l nimvg
nimvg:
LV NAME             TYPE       LPs     PPs     PVs  LV STATE      MOUNT POINT
explv               jfs2       199     199     1    open/syncd    /export
root@efsnim-p1:/root>

root@lpar112:/root> lspv
hdisk0          00c117e00a7d7827                    rootvg          active
hdisk1          none                                None
root@lpar112:/root>

Ansible on Control node and ibm.power_aix 1.8.3 collection.

[ckansible@efsnim-p1:/home/ckansible/ck-ans-02]$ ansible --version
ansible [core 2.14.13]
  config file = /home/ckansible/ck-ans-02/ansible.cfg
  configured module search path = ['/home/ckansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/freeware/lib/python3.9/site-packages/ansible
  ansible collection location = /home/ckansible/ck-ans-02/ibmcollections:/usr/share/ansible/collections
  executable location = /opt/freeware/bin/ansible.orig
  python version = 3.9.16 (main, Jun 28 2023, 12:45:03) [GCC 8.3.0] (/opt/freeware/bin/python3.9)
  jinja version = 3.1.2
  libyaml = False
[ckansible@efsnim-p1:/home/ckansible/ck-ans-02]$ ansible-galaxy collection list

# /home/ckansible/ck-ans-02/ibmcollections/ansible_collections
Collection    Version
------------- -------
ibm.power_aix 1.8.3

# /opt/freeware/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    5.2.0
...

Playbook, by reference "Migrating to AIX 7.3 with nimadm and Ansible" in url: https://community.ibm.com/community/user/power/blogs/chris-gibson1/2024/03/13/migrating-to-aix-73-with-nimadm-and-ansible

[ckansible@efsnim-p1:/home/ckansible/ck-ans-02]$ cat playbooks/cg_nim_alt_disk_migration_lpar112_hdisk0.yml
---
- name: "CK-PB - NIMADM playbook - Upgrading SP on AIX 7.3 TL02 SP00 to 7300-02-01-2346 with nimadm and Ansible"
  hosts: lpar112
  gather_facts: no

  collections:
    - ibm.power_aix
  tasks:
    - include_role:
        name: nim_alt_disk_migration
        apply:
          delegate_to: efsnim-p1
      vars:
        nimadm_cache_vg: nimvg
        nim_client: lpar112
        target_disk:
          disk_name: hdisk1
        lpp_source: lpp_source_aix73
        spot: spot_aix73
      register: nimadm_results

    - name: "T-1 - Debug: nimadm_results"
      ansible.builtin.debug: var=nimadm_results
...
[ckansible@efsnim-p1:/home/ckansible/ck-ans-02]$

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context I've test the simple playbook was included in ibm-power_aix-1.8.3 collection "demo_nim_alt_disk_migration.yml" getting same errors.

Rich-J-AIX commented 1 month ago

Looks like a bug in the latest version of the nim_alt_disk_migration role's main.yml to me.

'nimadm_phases_to_run' is undefined.

At the start of main.yml it runs

- name: "Fail when '{{ nimadm_phases_to_run }}' contains invalid characters"
  fail:
    msg: "{{ nimadm_phases_to_run }} contains alpha charcaters or a trailing comma, exiting"
  when: nimadm_phases_to_run is regex("[^0-9,]") or nimadm_phases_to_run[-1] == ','

This probably needs to be changed as follows:

- name: "Fail when '{{ nimadm_phases_to_run }}' contains invalid characters"
  fail:
    msg: "{{ nimadm_phases_to_run }} contains alpha charcaters or a trailing comma, exiting"
  when: 
     - nimadm_phases_to_run is defined
     - nimadm_phases_to_run is regex("[^0-9,]") or nimadm_phases_to_run[-1] == ','

There may be a more elegant way to fix it, but later on it is setting values to "N/A" is not set - and I think that would cause the regex to fail the playbook

SpringIBM commented 1 month ago

Hello there,

Due to my purpose to use ansible to perform AIX update service pack (SP) on NIM client (A.K.A: Ansible Managed node.)

Ansible Env:

To update SP on Managed ndoe/NIM Client. FROM: 7300-02-00-0000 TO: 7300-02-01-2346

Seems my mistaken and confuse to choose the example playbooks were included in ""ibm-power_aix-1.8.3" collection between "demo_nim_alt_disk_migration.yml" and "demo_nim.yml" file.

Now, I've modified the example playbook "demo_nim.yml" with below content.

And then run playbook above is took very short time and I verified "oslevel -s" were shown the AIX 7.3 Service Pack update successful.

Regards, Charin Kumjudpai.

schamola commented 1 month ago

Hi @SpringIBM ! We have a newer version of NIM Alt disk migration role present on Github, please use that one and let us know if the issue still persists.

This newer version would be available on Galaxy by next week.

ALutz273 commented 1 month ago

Had exactly the same problem. Thanks for the solution 👍