0

I have some package added in yum exclude list in /etc/yum.conf and I want to remove a specific package from a exclude list

example:

exclude=java* exclude=kernel* java* exclude=java* kernel* exclude=kernel* abc* java* def*

I tried to add # but that do not serve the purpose and add comments to all exclude statement.

- name: Comment Java exclusion
  replace:
    path: /etc/yum.conf
    regexp: '(.*java*)'
    replace: '#\1'

Added more case scenarios.

1 Answers1

1

Replace it with an empty string.

- name: Comment Java exclusion
  replace:
    path: /etc/yum.conf
    regexp: '(java\*\s*)'
    replace: ''

Changes to the regex:

  • .* would have removed the exclude= as well, so I removed it
  • The * needs to be escaped, it's a regex modifier
  • added \s* to remove trailing whitespace as well

EDIT

Even better:

- name: Comment Java exclusion
  replace:
    path: ~/ansible/test.blah
    regexp: '^(exclude=.*)java\*\s*'
    replace: '\1'

This makes sure that only the line starting with exclude= is affected and works even when java* is not the first item in the list.

Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79
  • grep exclude /etc/yum.conf exclude=java* exclude=kernel* java* exclude=java* kernel* exclude=kernel* abc* java* def* ----------------------------------------- $ grep exclude /etc/yum.conf exclude=exclude=kernel* exclude=kernel* exclude=kernel* abc* def* – Kamal Asdeo Nov 19 '21 at 14:49
  • It did not work – Kamal Asdeo Nov 19 '21 at 15:34
  • It did work perfectly in my tests prior to posting this. If it did not work for you please edit your question to provide more details. – Gerald Schneider Nov 19 '21 at 15:55
  • I have added below cases also in my question, Can you please check exclude=java* exclude=kernel* java* exclude=java* kernel* exclude=kernel* abc* java* def* – Kamal Asdeo Nov 19 '21 at 15:58