IBMi check if library already exists

50 views
Skip to first unread message

Paul Fenstermacher

unread,
Jan 10, 2023, 10:45:22 AM1/10/23
to ansible...@googlegroups.com

I want to include this create library task in playbooks that will run against IBMi systems. However, the playbook fails if the library already exists, and I need to know how to skip the command if the library is already there. In a CL program I would use MONMSG, is there something equivalent in Ansible?

 

  • Name: create library

Ibmi_cl_command:

Cmd: ‘CRTLIB LIB(libname)’

 

 

 

NOTICE: This electronic mail message and any files transmitted with it are intended
exclusively for the individual or entity to which it is addressed. The message,
together with any attachment, may contain confidential and/or privileged information.
Any unauthorized review, use, printing, saving, copying, disclosure or distribution
is strictly prohibited. If you have received this message in error, please
immediately advise the sender by reply email and delete all copies.

SP1 -77

unread,
Jan 16, 2023, 10:47:29 PM1/16/23
to ansible...@googlegroups.com
Hi,


This is not how you should write Ansible code.

For example,

Ansible is a declarative language and you should use a native module group which provides idempotence:

- name: Ensure 'hadoop’ group exists

  group:

    name: hadoop

    state: present


This way you don't have to check anything. The same task will either create a new group (status changed) or report that the group already exists (status ok). The state after executing will be the same: group hadoop is present.


Unfortunately not every action you want to perform has been implemented as native modules, that's why command module exists. But it should be used as a last resort.

What you are trying to achieve is possible using a custom python script, see references below;





The point is because Ansible is idempotent you shouldn’t have to worry about skipping the play because if you have properly written your Ansible code, then it will have no effect it already exists, to skip a play in Ansible this is done using the conditional execution (when) see below for an example:


https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_conditionals.html#the-when-statement

---

- name: register status of /tmp/toolbox.tar.gz

  stat:

    path: /tmp/toolbox.tar.gz

  register: toolbox_path


- name: install jetbrains toolbox

  # check if toolbox_path is a regular file

  when: "not toolbox_path.stat.exists"

  block:

    - name: download toolbox

      get_url:

        url: "https://download.jetbrains.com/toolbox/jetbrains-toolbox-{{ toolbox_version }}.tar.gz"

        dest: /tmp/toolbox.tar.gz


    - name: open toolbox

      unarchive:

        src: /tmp/toolbox.tar.gz

        dest: /opt/jetbrains-toolbox


Regards,

S.W



R







--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/DM6PR14MB4138EC4DD2ADC83BE4C31A01C3FF9%40DM6PR14MB4138.namprd14.prod.outlook.com.

SP1 -77

unread,
Jan 16, 2023, 10:54:17 PM1/16/23
to ansible...@googlegroups.com
See this guide for a comprehensive explanation:


--

SP1 -77

unread,
Jan 16, 2023, 11:17:16 PM1/16/23
to PFenste...@jackhenry.com, ansible...@googlegroups.com
This is the custom python script for creating a library using CL command CRTLIB 

Reply all
Reply to author
Forward
0 new messages