Home > OS >  How can I install package with version I need using "package"? | Ansible
How can I install package with version I need using "package"? | Ansible

Time:10-08

I want to install nginx with particular version. There are servers with different OS, so I want to avoid using similar typed "dnf", "apt", "yum" commands. By now it looks like this

 - name: Install ngnix
   dnf:
     name: nginx <= "{{ version_needed }}"
     state: latest
  when: (ansible_os_family == "RedHat")

...

# same commands with "yum" and "apt"

So I want to exclude "when" and change "dnf" with "package" but "dnf", "apt", "yum" accept using "<=" and "package" does not. Any suggestions or tricks?

P.S. The body

name: nginx <= "{{ version_needed }}"
state: latest

must stay due to problems with compatibility on some machines.

CodePudding user response:

Found solution myself.

The nginx <= "{{ version_needed }}" is still a case for me, so I ended up on using "use".

So now, it looks like this:

 - name: Install nginx
   package:
     name: nginx <= "{{ version_needed }}"
     state: present
     use: "{{ item }}"
   with_items:
   - dnf
   - yum
   - apt
  ignore_errors: yes

Now it works perfectly fine for me. Only workaround is "ignore_errors" because without this statement it stops on installing.

  • Related