A playbook for undoing yum history of certain packages.
This commit is contained in:
parent
641330e0ab
commit
c6719dda6b
1 changed files with 38 additions and 0 deletions
38
playbooks/manual/history_undo.yml
Normal file
38
playbooks/manual/history_undo.yml
Normal file
|
@ -0,0 +1,38 @@
|
|||
# requires --extra-vars="target='host1;host2;group etc' package='somepackage'"
|
||||
#
|
||||
# This playbook searches through the yum history for the latest transaction
|
||||
# involving a particular package. Once it finds it, it will undo that
|
||||
# transaction.
|
||||
#
|
||||
# Note, this playbook is not idempotent. Say you mistakenly installed httpd on
|
||||
# all the virthosts. If you run this once, it will undo those transactions. If
|
||||
# you run it again, it will undo that previous *undo*.
|
||||
|
||||
- name: Find and undo the latest yum transaction involving a $PACKAGE
|
||||
hosts: "{{ target }}"
|
||||
user: root
|
||||
|
||||
tasks:
|
||||
- name: find the ID of the last yum transaction
|
||||
shell: yum history package {{ package }} | sed -n 3p | awk -F "|" '{ print $1 }' | tr -d ' '
|
||||
register: transaction_id
|
||||
|
||||
# If transaction_id.stderr == "", then that means that the $PACKAGE we're
|
||||
# looking for was never installed; it does not appear in the yum history.
|
||||
- debug: var=transaction_id.stdout
|
||||
when: transaction_id.stderr == ""
|
||||
|
||||
- name: get info on that transaction
|
||||
command: yum history info {{ transaction_id.stdout }}
|
||||
register: transaction_info
|
||||
when: transaction_id.stderr == ""
|
||||
|
||||
- debug: var=transaction_info.stdout_lines
|
||||
when: transaction_id.stderr == ""
|
||||
|
||||
#- pause: seconds=30 prompt="Undoing that yum transaction. Abort if this is wrong."
|
||||
# when: transaction_id.stderr == ""
|
||||
|
||||
- name: Okay.. undo that transaction now
|
||||
command: yum -y history undo {{ transaction_id.stdout }}
|
||||
when: transaction_id.stderr == ""
|
Loading…
Add table
Add a link
Reference in a new issue