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

sap_vm_preconfigure: implement ansible-lint changes #554

Merged
merged 4 commits into from
Jan 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
- name: "Set the grub.cfg location RHEL"
set_fact:
__sap_vm_preconfigure_uefi_boot_dir: /boot/efi/EFI/redhat/grub.cfg
when:
when:
- ansible_distribution == 'RedHat'

- name: "Set the grub.cfg location SLES"
set_fact:
__sap_vm_preconfigure_uefi_boot_dir: /boot/efi/EFI/BOOT/grub.cfg
when:
- ansible_distribution == 'SLES' or ansible_distribution == 'SLES_SAP'
when:
- ansible_distribution == 'SLES' or ansible_distribution == 'SLES_SAP'

- name: "Run grub-mkconfig (UEFI mode)"
command: "grub2-mkconfig -o {{ __sap_vm_preconfigure_uefi_boot_dir }}"
Expand Down
96 changes: 48 additions & 48 deletions roles/sap_vm_preconfigure/tasks/detect_platform/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@

# TODO: detection based on multiple facts and providing one standard
# name for use as platform type in related include files
# cloud_aliyun_ecs_vm, cloud_aws_ec2_vs, cloud_gcp_ce_vm, cloud_ibmcloud_powervs, cloud_ibmcloud_vs, cloud_msazure_vm, hyp_ibmpower_lpar, hyp_redhat_ocp_virt_vm, hyp_redhat_rhel_kvm_vm, hyp_vmware_vsphere_vm
# cloud_aliyun_ecs_vm, cloud_aws_ec2_vs, cloud_gcp_ce_vm, cloud_ibmcloud_powervs, cloud_ibmcloud_vs, cloud_msazure_vm,
# hyp_ibmpower_lpar, hyp_redhat_ocp_virt_vm, hyp_redhat_rhel_kvm_vm, hyp_vmware_vsphere_vm

- name: "SAP VM Preconfigure - Check if platform is Amazon Web Services EC2 Virtual Server"
when:
- ansible_system_vendor == 'Amazon EC2'
ansible.builtin.set_fact:
sap_vm_platform: cloud_aws_ec2_vs

#- name: "SAP VM Preconfigure - Check if platform is Google Cloud Compute Engine Virtual Machine"
# - name: "SAP VM Preconfigure - Check if platform is Google Cloud Compute Engine Virtual Machine"
# when:
# - ansible_product_name == 'Google Compute Engine'
# ansible.builtin.set_fact:
Expand All @@ -61,14 +62,14 @@
ansible.builtin.set_fact:
sap_vm_platform: cloud_ibmcloud_vs

#- name: "SAP VM Preconfigure - Check if platform is Microsoft Azure Virtual Machine"
# - name: "SAP VM Preconfigure - Check if platform is Microsoft Azure Virtual Machine"
# when:
# - ansible_chassis_vendor == 'Virtual Machine'
# - ansible_product_name == 'Microsoft Corporation'
# ansible.builtin.set_fact:
# sap_vm_platform: cloud_msazure_vm

#- name: "SAP VM Preconfigure - Check if platform is VMware vSphere"
# - name: "SAP VM Preconfigure - Check if platform is VMware vSphere"
# when:
# - ansible_virtualization_type == 'VMware'
# ansible.builtin.set_fact:
Expand All @@ -79,53 +80,52 @@
when: sap_vm_platform == cloud_aws_ec2_vs
block:

- name: (AWS) Get instance metadata token
ansible.builtin.uri:
headers:
X-aws-ec2-metadata-token-ttl-seconds: 21600
method: PUT
return_content: true
url: http://169.254.169.254/latest/api/token
register: detect_cloud_provider_aws_token
changed_when: false
ignore_errors: true

- name: (AWS) Get instance metadata ami-id
ansible.builtin.uri:
headers:
X-aws-ec2-metadata-token: "{{ detect_cloud_provider_aws_token.content }}"
method: GET
return_content: true
url: http://169.254.169.254/latest/meta-data/ami-id
register: detect_cloud_provider_aws_ami_id
changed_when: false
ignore_errors: true

- name: (AWS) Fail if cannot reach Instance Metadata Service
ansible.builtin.fail:
msg: Detected MS Azure, but could not confirm with the Instance Metadata Service
when:
- detect_cloud_provider_aws_ami_id.failed
- name: (AWS) Get instance metadata token
ansible.builtin.uri:
headers:
X-aws-ec2-metadata-token-ttl-seconds: 21600
method: PUT
return_content: true
url: http://169.254.169.254/latest/api/token
register: detect_cloud_provider_aws_token
changed_when: false
ignore_errors: true

- name: (AWS) Get instance metadata ami-id
ansible.builtin.uri:
headers:
X-aws-ec2-metadata-token: "{{ detect_cloud_provider_aws_token.content }}"
method: GET
return_content: true
url: http://169.254.169.254/latest/meta-data/ami-id
register: detect_cloud_provider_aws_ami_id
changed_when: false
ignore_errors: true

- name: (AWS) Fail if cannot reach Instance Metadata Service
ansible.builtin.fail:
msg: Detected MS Azure, but could not confirm with the Instance Metadata Service
when:
- detect_cloud_provider_aws_ami_id.failed


- name: SAP VM Preconfigure - confirm Microsoft Azure Virtual Machine
when: sap_vm_platform == cloud_msazure_vm
block:

- name: (Azure) Get instance metadata
ansible.builtin.uri:
headers:
Metadata: true
method: GET
url: http://169.254.169.254/metadata/instance/compute?api-version=2021-10-01
register: detect_cloud_provider_azure_instance_metadata
changed_when: false
ignore_errors: true

- name: (Azure) Fail if cannot reach Instance Metadata Service
ansible.builtin.fail:
msg: Detected MS Azure, but could not confirm with the Instance Metadata Service
when:
- detect_cloud_provider_azure_instance_metadata.json.azEnvironment is not defined
- detect_cloud_provider_azure_instance_metadata.json.azEnvironment != "AzurePublicCloud"

- name: (Azure) Get instance metadata
ansible.builtin.uri:
headers:
Metadata: true
method: GET
url: http://169.254.169.254/metadata/instance/compute?api-version=2021-10-01
register: detect_cloud_provider_azure_instance_metadata
changed_when: false
ignore_errors: true

- name: (Azure) Fail if cannot reach Instance Metadata Service
ansible.builtin.fail:
msg: Detected MS Azure, but could not confirm with the Instance Metadata Service
when:
- detect_cloud_provider_azure_instance_metadata.json.azEnvironment is not defined
- detect_cloud_provider_azure_instance_metadata.json.azEnvironment != "AzurePublicCloud"
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
- name: Assert - Check tuned profile
block:
- name: Get tuned profile
command: tuned-adm active
ansible.builtin.command: tuned-adm active
register: __sap_vm_preconfigure_register_tuned_profile_assert
changed_when: __sap_vm_preconfigure_register_tuned_profile_assert.rc != 0

- name: Verify tuned profile
assert:
ansible.builtin.assert:
that: "'Current active profile: sap-hana-kvm-host' in __sap_vm_preconfigure_register_tuned_profile_assert.stdout"
fail_msg: "FAIL: tuned profile is not sap-hana-kvm-guest"
success_msg: "PASS: tuned profile is sap-hana-kvm-guest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
# tasks file for sap_vm_preconfigure

- name: Trigger tuned profile sap-hana-kvm-guest activation
include_tasks: set-tuned-profile.yml
ansible.builtin.include_tasks: set-tuned-profile.yml

- name: Set filename prefix to empty string if role is run in normal mode
set_fact:
ansible.builtin.set_fact:
__sap_vm_preconfigure_fact_assert_prefix: ""
when: not sap_vm_preconfigure_assert|d(false)

- name: Prepend filename with assert string if role is run in assert mode
set_fact:
ansible.builtin.set_fact:
__sap_vm_preconfigure_fact_assert_prefix: "assert-"
when: sap_hypervisor_node_preconfigure_assert|d(false)

- include_tasks: '{{ __sap_vm_preconfigure_fact_assert_prefix }}set-tuned-profile.yml'
- name: Include '{{ __sap_vm_preconfigure_fact_assert_prefix }}set-tuned-profile.yml'
ansible.builtin.include_tasks: '{{ __sap_vm_preconfigure_fact_assert_prefix }}set-tuned-profile.yml'
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---
- name: Create tuned profile directory /usr/lib/tuned/sap-hana
file:
ansible.builtin.file:
path: /usr/lib/tuned/sap-hana
state: directory
mode: "0755"

- name: Create sap-hana tuned profile
copy:
ansible.builtin.copy:
dest: "/usr/lib/tuned/sap-hana/tuned.conf"
mode: "0644"
content: |
#
# tuned configuration
Expand Down Expand Up @@ -34,14 +36,15 @@


- name: Create tuned profile directory /usr/lib/tuned/sap-hana-kvm-guest
file:
ansible.builtin.file:
path: /usr/lib/tuned/sap-hana-kvm-guest
mode: "0755"
state: directory

- name: Add haltpoll.sh for tuned sap-hana-kvm-guest
copy:
ansible.builtin.copy:
dest: "/usr/lib/tuned/sap-hana-kvm-guest/haltpoll.sh"
mode: 0744
mode: "0744"
content: |
#!/bin/bash

Expand All @@ -53,8 +56,9 @@


- name: Create sap-hana-kvm-guest tuned profile
copy:
ansible.builtin.copy:
dest: "/usr/lib/tuned/sap-hana-kvm-guest/tuned.conf"
mode: "0644"
content: |
#
# tuned configuration
Expand Down Expand Up @@ -82,4 +86,6 @@
cmdline_saphana=skew_tick=1

- name: Activate tuned profile
command: tuned-adm profile sap-hana-kvm-guest
ansible.builtin.command: tuned-adm profile sap-hana-kvm-guest
register: __sap_provision_vm_register_tuned_sap_hana_kvm_guest_status
changed_when: __sap_provision_vm_register_tuned_sap_hana_kvm_guest_status.rc != 0