replace this command if [[ $LASTKERNEL != $CURRENTKERNEL ]]; then Set reboot flag touch…
- User
replace this command if [[ CURRENT_KERNEL ]]; then # Set reboot flag touch /tmp/reboot echo "KERNEL_CHANGED" else echo "No KERNEL Change Detected" fi
- Assistant
if [ "CURRENT_KERNEL" ]; then # Set reboot flag touch /tmp/reboot echo "KERNEL_CHANGED" else echo "No KERNEL Change Detected" fi
- User
- name: Reboot the machine (Wait for 5 min or 300 Sec) reboot: reboot_timeout: 300 test_command: uptime when: kernel_update_status.stdout == "KERNEL_CHANGED" register: reboot_status
- Assistant
Here is the Ansible task with the YAML syntax you provided:
- name: Reboot the machine (Wait for 5 min or 300 Sec) reboot: reboot_timeout: 300 test_command: uptime when: kernel_update_status.stdout == "KERNEL_CHANGED" register: reboot_statusPlease note this is an Ansible playbook task and not a standalone script. You should include this task in your Ansible playbook.
- User
How would you modify this playbook to prompt users before rebooting, but for ansile tower?
- Assistant
In Ansible Tower, you can use a "Survey" to prompt a user for input before running a playbook. Here's how to modify the playbook to conditionally reboot the system based on the user's input.
- First, let's add a variable
user_confirm_rebootin the playbook:
--- - hosts: all vars: user_confirm_reboot: false tasks: # ...your other tasks - name: Reboot the machine (Wait for 5 min or 300 Sec) reboot: reboot_timeout: 300 test_command: uptime when: kernel_update_status.stdout == "KERNEL_CHANGED" and user_confirm_reboot | bool register: reboot_statusThe
user_confirm_rebootvariable is set tofalseby default, so the system won't reboot unless the variable is overridden.- Create a Survey in the Ansible Tower:
- Go to the "Templates" section in the Ansible Tower.
- Click on the template that you are using to run this playbook.
- In the template page, click on the "Add Survey" button in the top right corner.
- In the "Add/Edit Survey" page, create a new survey question with the following details:
- Prompt: "Do you want to reboot the system?"
- Answer Variable Name:
user_confirm_reboot - Answer Type: "Multiple Choice (single select)"
- Multiple Choice Options:
yes no - Save the survey.
Now, when the playbook is run via Ansible Tower and the survey is set to display, the users will be prompted for their response. The playbook will reboot the system only if the user selects "yes" as the answer.
- First, let's add a variable