Prady_A
(Prady A)
August 14, 2023, 9:21am
1
Hi folks
I want to optimize the code here
Existing code:
package:
name: “{{ item }}”
state: present
with_items:
vim
lvm2
xyz
when: is_USA
Now I don’t want to install xyz PACKAGE for RHEL 9 server only then I ve to rewrite the separate code for xyz package like below or any optimization is possible in the existing code
utoddl
(Todd Lewis)
August 14, 2023, 11:06am
2
Here’s my solution. Whether you wish to go there is a different question.
---
- name: Prady A example 1
hosts: localhost
vars:
is_usa: true
tasks:
- name: Install packages with logical list
ansible.builtin.package:
# requires "ansible-galaxy collection install utoddl.logical"
name: "{{ rpms | utoddl.logical.logical }}"
state: present
vars:
rpms:
- vim
- lvm2
- if:
- and:
- "{{ is_usa }}"
- "{{ ansible_distribution_major_version | int <= 9 }}"
- xyz
See https://galaxy.ansible.com/utoddl/logical for details and examples.
Prady_A
(Prady A)
August 14, 2023, 1:07pm
3
Super cool . That’s what I was try in
pseudo code…
Thanks a ton