Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run shell command to rescan hard disks on Flatcar #80

Merged
merged 5 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default_remote_user = root
display_skipped_hosts = False
remote_tmp = /tmp
retry_files_enabled = False
callback_whitelist = timer
callbacks_enabled = timer

# When Ansible version >= 2.10, and Ansible collections are not installed
# in the default path, then set this parameter to the path of installed collections.
Expand Down
13 changes: 12 additions & 1 deletion linux/deploy_vm/flatcar/ignition_config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
}
]
},
"systemd": {},
"systemd": {
"units":[{
"name": "update-engine.service",
"enabled": false,
"mask": true
},
{
"name": "locksmithd.service",
"enabled": false,
"mask": true
}]
},
"storage": {}
}
16 changes: 9 additions & 7 deletions linux/utils/check_service_status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
expected_service_status: ""
when: expected_service_state == 'absent'

- name: "Validate the value of 'expected_service_state' and 'expected_service_status'"
assert:
that:
- expected_service_state is defined
- expected_service_state in ['active', 'inactive', 'running', 'stopped', 'absent']
- (expected_service_state == 'absent') or (expected_service_status is defined and expected_service_status in ['enabled', 'disabled'])
fail_msg: "Invalid parameters: expected_service_state={{ expected_service_state | default('undefined') }}, expected_service_status={{ expected_service_status | default('undefined') }}"
- name: "Check the value of 'expected_service_state' and 'expected_service_status'"
fail:
msg: "Invalid parameters: expected_service_state={{ expected_service_state | default('undefined') }}, expected_service_status={{ expected_service_status | default('undefined') }}"
when: >
(expected_service_state is undefined) or
(expected_service_state not in ['active', 'inactive', 'running', 'stopped', 'absent']) or
(expected_service_state != 'absent' and
(expected_service_status is undefined or
expected_service_status not in ['enabled', 'disabled']))

- include_tasks: get_service_info.yml

Expand Down
3 changes: 2 additions & 1 deletion linux/utils/enable_disable_cloudinit_cfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
# Enable cloud-init services
- include_tasks: service_operation.yml
vars:
enable_service: 'yes'
service_enabled: true
service_state: "started"
loop:
- cloud-init-local
- cloud-init
Expand Down
52 changes: 22 additions & 30 deletions linux/utils/service_operation.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
# This task is used to enable/disable service
- name: "Set variables for enable service"
set_fact:
enable: "Enable"
mask: "not masked"
enabled: "enabled"
when: enable_service == "yes"
- name: "Set variables for disable service"
set_fact:
enable: "Disable"
mask: "masked"
enabled: "disabled"
when: enable_service == "no"
- name: "{{ enable }} service: {{ service_name }} and ensure it is {{ mask }}"
systemd:
# Parameters:
# service_name: The service name to be configured
# service_enabled: True of false to enable or disable service
# service_state: The service state: reloaded, restarted, started, or stopped
#
- name: "Validate service state"
fail:
msg: "Invalid parameter service_enabled or service_state. service_enabled: {{ service_enabled }}, service_state: {{ service_state }}"
when: >
(service_enabled is undefined and service_state is undefined) or
(service_enabled is defined and service_enabled | bool not in [true, false]) or
(service_state is defined and service_state not in ['reloaded', 'restarted', 'started', 'stopped'])

- name: "Update service {{ service_name }}, enabled: {{ service_enabled }}, state: {{ service_state }}"
service:
name: "{{ service_name }}"
enabled: "{{ enable_service }}"
daemon_reload: yes
enabled: "{{ service_enabled }}"
state: "{{ service_state }}"
delegate_to: "{{ vm_guest_ip }}"
- name: "Get {{ service_name }} is-enabled status"
command: "systemctl is-enabled {{ service_name }}"
register: service_status
delegate_to: "{{ vm_guest_ip }}"
changed_when: false
ignore_errors: true
- name: "Print sevice is-enabled output"
debug: var=service_status
when: enable_debug is defined and enable_debug
- name: "Assert {{ service_name }} is {{ enabled }}"
assert:
that:
- service_status.stdout.count(enabled) > 0
fail_msg: "Failed, {{ service_name }} is not expected {{ enabled }}"

- include_tasks: check_service_status.yml
vars:
expected_service_state: "{{ 'active' if service_state in ['started', 'restarted'] else 'inactive' }}"
expected_service_status: "{{ 'enabled' if service_enabled else 'disabled' }}"
68 changes: 39 additions & 29 deletions linux/vhba_hot_add_remove/wait_device_list_changed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,46 @@

# Rescan SCSI bus
- block:
- name: "Set SCSI command tools package name"
set_fact:
sg3_utils_pkg: |-
{%- if guest_os_ansible_distribution in ["Ubuntu", "Debian"] -%}sg3-utils
{%- else -%}sg3_utils{%- endif -%}
- block:
- name: "Set SCSI command tools package name"
set_fact:
sg3_utils_pkg: |-
{%- if guest_os_ansible_distribution in ["Ubuntu", "Debian"] -%}sg3-utils
{%- else -%}sg3_utils{%- endif -%}

# Install SCSI command tools
- include_tasks: ../utils/get_installed_package_info.yml
vars:
package_name: "{{ sg3_utils_pkg }}"

- include_tasks: ../utils/install_uninstall_package.yml
vars:
package_name: "{{ sg3_utils_pkg }}"
package_state: "present"
update_cache: True
when:
- package_info is defined
- package_info | length == 0

- name: "Rescan all scsi devices"
command: "/usr/bin/rescan-scsi-bus.sh -a -r"
register: rescan_scsi_result
delegate_to: "{{ vm_guest_ip }}"

- name: "Print result of rescanning scsi"
debug: var=rescan_scsi_result.stdout_lines
when:
- rescan_scsi_result is defined
- rescan_scsi_result.stdout_lines
when: guest_os_ansible_distribution != 'Flatcar'

# Install SCSI command tools
- include_tasks: ../utils/get_installed_package_info.yml
vars:
package_name: "{{ sg3_utils_pkg }}"

- include_tasks: ../utils/install_uninstall_package.yml
vars:
package_name: "{{ sg3_utils_pkg }}"
package_state: "present"
update_cache: True
when:
- package_info is defined
- package_info | length == 0

- name: "Rescan all scsi devices"
command: "/usr/bin/rescan-scsi-bus.sh -a -r"
register: rescan_scsi_result
delegate_to: "{{ vm_guest_ip }}"

- name: "Print result of rescanning scsi"
debug: var=rescan_scsi_result.stdout_lines
when:
- rescan_scsi_result is defined
- rescan_scsi_result.stdout_lines
- block:
- name: "Rescan all hard disks"
shell: |
for i in `find /sys/ -iname rescan`;do echo 1 >$i; done;
for i in `find /sys/ -iname scan`;do echo "- - -" >$i; done;
delegate_to: "{{ vm_guest_ip }}"
when: guest_os_ansible_distribution == 'Flatcar'
when: new_disk_ctrl_type == 'lsilogic'

- block:
Expand Down