2

I am using Spacewalk release 2.9 to manage my CentOS Linux server. using below spacecmd command to push the new packages. I want to reboot the server once all the packages are installed on the machine. I am unsure how to monitor package upgrade and issue the reboot command. Any recommendations to achieve this? I would like to use Ansible playbook to do this reboot.

spacecmd  system_upgradepackage  <hostname> '*' -y

Thanks SR

sfgroups
  • 330
  • 4
  • 7
  • 25
  • Above `spacecmd` command invokes the packages to be pushed, it won't wait until task completed, we need to wait patches pushed and reboot the server. – sfgroups Aug 22 '19 at 15:34

2 Answers2

0

Ansible can reboot the server without using spacecmd, using the reboot command.

- name: Upgrading via spacewalk
  shell: spacecmd  system_upgradepackage  <hostname> '*' -y
- name: Reboot after upgrades
  shell: reboot
  async: 0
  poll: 0
- name: Waiting for host to come up
  local_action: wait_for host={{ ansible_ssh_host }} state=started

Adapted from: https://www.linux.com/tutorials/ansible-reboot-server-play-book-and-wait-it-come-back

oxr463
  • 1,240
  • 1
  • 10
  • 19
  • we need to check patches pushed, before invoking os reboot. otherwise system will reboot in middle of patching. – sfgroups Aug 22 '19 at 15:37
  • we need to wait until this command output comes zero `spacecmd system_listupgrades |wc -l` Is it possible to check with ansible? – sfgroups Feb 19 '20 at 17:10
0

I'm not familiar with spacecmd, but you can use the wait_for module to monitor the PID.

From docs:

- name: Wait until the process is finished and PID was destroyed
  wait_for:
    path: /proc/3466/status
    state: absent
Siva
  • 9,017
  • 8
  • 56
  • 86