dell / ansible-powermax

Ansible Modules for Dell PowerMax
GNU General Public License v3.0
36 stars 35 forks source link

Module is not idempotent when creating a new host #13

Closed remkolodder closed 2 years ago

remkolodder commented 2 years ago

We are currently deploying our PowerMax setup via Ansible and we notice that when creating a new host, the code doesn't appear to be idempotent.

See attached image;

powermax_new_host_github

The following code is being used to deploy that ( a bit sanitized);

- name: "Create PowerMax host for {{ host }}"
dellemc.powermax.dellemc_powermax_host:
unispherehost: "{{ host }}"
universion: "{{ version }}"
verifycert: "{{ verifycert }}"
serial_no: "{{ serial }}"
user: "{{ username }}"
password: "{{ password }}"
host_name: "{{ host_name"
host_type: "default"
state: "present"
initiator_state: "present-in-host"
initiators: "{{ initiators }}"
rawstorage commented 2 years ago

Hi, the error doesn't appear to be one with idempotency but that the initiator is already in a host. Have you verified that the initiator is not part of a host with a different name.?

rawstorage commented 2 years ago

run1

run2 error

I'm able to reproduce this issue easily but it's not an idempotency issue, the error is due to initiator being in another host. See images.

rawstorage commented 2 years ago

Hi @remkolodder, can you confirm that this was your issue and close the issue?

remkolodder commented 2 years ago

Hi Paul,

I will be checking this today. Cannot confirm this yet.

remkolodder commented 2 years ago

Hi Paul,

We figured out the issues, we are re-using existing machines with a different name in the current powermax setup. they are prefixed with a prefix, and when redeploying such a machine we expected the hosts part to rename the host(s).

That doesn't happen so we work around it by sniffing the log message, if the machine is already there, we do a different task and rename it.

That looks like this:

- name: "Create PowerMax host"
  when: (host.split('.')[0]) not in powermax_host_facts.Hosts
  dellemc.powermax.dellemc_powermax_host:
    unispherehost: "{{ host }}"
    universion: "{{ version }}"
    verifycert: "{{ verifycert }}"
    serial_no: "{{ serial }}"
    user: "{{ username }}"
    password: "{{ password }}"
    host_name: "{{ host.split('.')[0] }}"
    host_type: "default"
    state: "present"
    initiator_state: "present-in-host"
    initiators: "{{ initiators }}"
  register: host_add
  failed_when: >
    (host_add.msg is defined) and
    'is already part of a host' not in host_add.msg

- name: Rename host
  when: >
    (host_add.msg is defined) and
    'is already part of a host' in host_add.msg
  dellemc.powermax.dellemc_powermax_host:
    unispherehost: "{{ host }}"
    universion: "{{ version }}"
    verifycert: "{{ verifycert }}"
    serial_no: "{{ serial }}"
    user: "{{ username }}"
    password: "{{ password }}"
    host_name: "ig_{{ (host.split('.')[0] | replace('-', '_')) }}"
    new_name: "{{ host.split('.')[0] }}"
    state: "present"

Thanks for your efforts, it would be great when we can auto rename something but we can work around it like this as well :)

rawstorage commented 2 years ago

No problem, Auto rename could be dangerous. It's advised to validate the inputs or if you are comfortable with renaming automatically implement logic like you have done. For out of the box functionality we need to ensure we are doing what will work in the normal workflows. As you point out rename functionality is implemented but you need to choose when to use if we did this idempotency would be gone.

Sent from a mobile device. Typos are inevitably going to happen. Please excuse them.


From: remkolodder @.***> Sent: Tuesday 22 February 2022, 16:27 To: dell/ansible-powermax Cc: Martin, Paul; Comment Subject: Re: [dell/ansible-powermax] Module is not idempotent when creating a new host (Issue #13)

[EXTERNAL EMAIL]

Hi Paul,

We figured out the issues, we are re-using existing machines with a different name in the current powermax setup. they are prefixed with a prefix, and when redeploying such a machine we expected the hosts part to rename the host(s).

That doesn't happen so we work around it by sniffing the log message, if the machine is already there, we do a different task and rename it.

That looks like this:

Thanks for your efforts, it would be great when we can auto rename something but we can work around it like this as well :)

— Reply to this email directly, view it on GitHub [github.com]https://urldefense.com/v3/__https://github.com/dell/ansible-powermax/issues/13*issuecomment-1047976493__;Iw!!LpKI!xZOUccEIDDLJzWcLzJqzlp89ozeiRMfM4KhAbyc9SIb7y5KEuNvYm0-su8kz9JTG$, or unsubscribe [github.com]https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AF7FWPMKC74KJSGCQMAPG33U4O2OBANCNFSM5O6PJTCA__;!!LpKI!xZOUccEIDDLJzWcLzJqzlp89ozeiRMfM4KhAbyc9SIb7y5KEuNvYm0-suxwyTLCN$. Triage notifications on the go with GitHub Mobile for iOS [apps.apple.com]https://urldefense.com/v3/__https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675__;!!LpKI!xZOUccEIDDLJzWcLzJqzlp89ozeiRMfM4KhAbyc9SIb7y5KEuNvYm0-su2Zqo87C$ or Android [play.google.com]https://urldefense.com/v3/__https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign*3Dnotification-email*26utm_medium*3Demail*26utm_source*3Dgithub__;JSUlJSU!!LpKI!xZOUccEIDDLJzWcLzJqzlp89ozeiRMfM4KhAbyc9SIb7y5KEuNvYm0-su-XW2InX$. You are receiving this because you commented.Message ID: @.***>

Internal Use - Confidential