Check is a package exists - Ansible

0 votes
I would like to check if a specific package exists in my ansible. Also, I do not want to update it? How do I do it?
Mar 6, 2019 in Ansible by Kavya
8,149 views

2 answers to this question.

0 votes

Hey @Kavya, to ensure a package is installed, but don’t update it, you can use the following command:

$ ansible webservers -m yum -a "name=acme state=present"

It checks for a yum package called acme in all the servers listed under the group webservers.

answered Mar 6, 2019 by Yogesh
+1 vote
Hey There,

@here is an example for your query.

- name: "Search ntpstat package"
  shell: "apt-cache search ntpstat"
  register: package_searched

- name: "Check if ntpstat is installed or not"
  command: dpkg-query -l ntpstat
  register: dpkg_check

- name: "Install ntpstat"
  apt:
    name: ntpstat
    state: latest
    force: yes
  when: dpkg_check.stdout == ""
  ignore_errors: yes

- name: "ntp synchronisation from the server"
  command: ntpstat
  ignore_errors: true
answered May 6, 2020 by Rajat
• 160 points

Related Questions In Ansible

0 votes
1 answer

Check for certain package with specific version exists - Ansible

Hey @Kavya, to check if a package ...READ MORE

answered Mar 6, 2019 in Ansible by Devika
2,848 views
0 votes
1 answer

Ansible task to determine if a path exists and is a symlink

Hi @neha, you can write your task ...READ MORE

answered Apr 2, 2019 in Ansible by Alok
7,645 views
+1 vote
2 answers

Running ansible command on a single server when it is deployed to multiple servers

You can try the run_once attribute: Example from ...READ MORE

answered Jun 14, 2018 in Ansible by DareDev
• 6,890 points
2,484 views
0 votes
1 answer
+1 vote
1 answer

Is it possible to append a large amount of text to a file using Ansible?

Here is concept which you can follow. blockinfile is ...READ MORE

answered Jul 30, 2018 in Ansible by Atul
• 10,240 points
14,747 views
+1 vote
1 answer
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,064 views
+2 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP