1

On some Centos VMs, I have a few MySQL packages to remove (via yum) and then install MariaDB (via rpm), all in a shell script. I use yum for removal:

yum remove -y mysql-community-client yum remove -y mysql-community-release yum remove -y mysql-community-libs yum remove -y mysql-community-common 

Now, on some VMs, maybe the client package is not installed, so yum says:

No Match for argument: mysql-community-client Determining fastest mirrors Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=stock error was 14: PYCURL ERROR 7 - "couldn't connect to host" 

I know that connection failure is because of our FireWall and such.

My question is:
Can yum be told to ignore missing packages?
Or at least simply fail with No Match for argument, without connecting to mirrors and such?

Question title refers to the fact that yum remove -y mysql-community-client followed by yum remove -y mysql-community-client will make it connect to mirrors, whereas I want it to say "package uninstalled" followed by "package already uninstalled".

Rephrasing the problem: Issue is not with RPM ( I only mentioned that for completeness of my problem ), the problem is with yum. yum remove X will remove X, if it is installed. If it is not installed, it will search in the mirrors which I want to avoid. I want yum to say "X not installed" and exit.

2
  • why don't you do yum list | grep mysql and if it shows mysql, then only call yum remove.... Commented Nov 4, 2015 at 11:35
  • @MadhavanKumar , yes , that is what I have to finally do in the script, as a workaround. My question is : How to make yum itself do this ? When executing "yum remove mysql-community-client", it asks "Y/N?" and so I added "-y" to get "yum remove -y mysql-community-client". Now it does not ask "Y/N?". Is there some similar flag like --skip-missing-packages, which will make yum not search in the mirrors ? Commented Nov 4, 2015 at 12:21

3 Answers 3

1

We can discuss for long time how the yum behave or should behave, but to make long story short:

yum --cacheonly remove -y mysql-community-client 

is what you probably want.

2
  • Excellent !! Exactly what I was looking for !! Commented Nov 4, 2015 at 14:48
  • "yum --cacheonly remove -y mysql-community-client", when repeated, shows "Loaded plugins: fastestmirror, security .... Setting up Remove Process .... No Match for argument: mysql-community-client .... Package(s) mysql-community-client available, but not installed .... No Packages marked for removal" Commented Nov 4, 2015 at 14:51
1

If I understood correctly, you want to prevent network access, disable plugins and only uninstall those mysql-community packages which are installed currently. So how about

yum --disablerepo="*" --noplugins remove "*mysql-community*" -y 

and that will only match any installed package matched by the glob "*mysql-community*". Although in general I'd personally never use -y flag together with remove.

If you only want to selectively uninstall specific packages if installed, then the answer from Thomas is exactly what you need.

1
  • @msuchy has given the answer I was looking for. I used "--cacheonly", which works fine. When I get the chance, I will test "--disablerepo" & "---noplugins", which may be a valid alternative, so +1. Commented Nov 5, 2015 at 3:32
0

If you install a package using rpm rather than from a yum repository, yum will not know how to determine when the rpm has been removed, because there is no relevant repository to refer to. So part of that (MariaDB) cannot be made idempotent.

If you want to make your script idempotent, a better approach would be to use rpm -q for the given package to determine if it is installed, and use that result to decide whether to run yum.

If you use rpm for installing a package, yum will not notice immediately, but will warn you when you ask it to update your system that the RPM database was installed outside yum. For this reason, you should use yum install to install the MariaDB packages from your set of RPMs.

2
  • the problem is not with RPM ( I only mentioned that for completeness of my problem ) , the problem is with yum. "yum remove X" will remove X , if it is installed. If it is not installed, it will search in the mirrors which I want to avoid. I want yum to say "X not installed" and exit. Commented Nov 4, 2015 at 12:13
  • Sure: and if you want to make your script idempotent, you should use repeatable features, not that those that vary according to conditions beyond your control. Testing with rpm gives the information you need without doing network access. Commented Nov 4, 2015 at 14:03

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.