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

Merged telegraf code for all hosts #61

Merged
merged 3 commits into from
Oct 2, 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
55 changes: 55 additions & 0 deletions ansible/Ansible_Guidelines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Ansible Best Practices and Guidelines

=====================================

This files helps you with the guidelines and the best practices that you can follow, when working on the OPI Ansible scripts. Also go through the guidelines stated on contributing for the OPI Lab repository for a general overview and the GitHub process associated with it.

## Table of Contents

---

1. [General Best Practices](#general-best-practices)
2. [Project Structure](#project-structure)
3. [Playbooks](#playbooks)
4. [Code Readability and Style](#code-readability-and-style)
5. [Additional Tips](#additional-tips)

## General Best Practices

---

Always test you code before raising a Pull Request and use version control and follow coding standards. Avoid unnecessary complexity and use Ansible's built-in features.

## Project Structure

---

This shall be updated soon with the new folder structure that we will be implementing.

- **Organize playbooks**: Use a clear directory structure for playbooks and roles.
- **Use top-level playbooks**: Create top-level playbooks that orchestrate other playbooks, example: site.yml (currently orchestrates all the other playbooks in the repository).
- **Separate configuration and deployment**: Use separate playbooks for configuration and deployment tasks.

## Playbooks

---

- **Use descriptive variable names**: Use clear and descriptive names for variables.
- **Avoid duplicating code**: Try to re-use the same code with different conditional variables like `when` to avoid code duplication.
- **Follow module development guidelines**: Adhere to Ansible's module development best practices.
- **Avoid Ansible-lint errors**: Once you have completed the development of a script, please run `ansible-lint` on your playbook and make sure there are no linting errors.
- **Use native modules**: Prefer native Ansible modules over the `command` module.
- **Avoid complex module options**: Keep module options simple and focused, and always check the official ansible documentation for help on the module options here [Ansible documentation](https://docs.ansible.com/ansible/latest/index.html)

## Code Readability and Style

---

- **Add comments**: Include comments to explain the purpose of tasks and variables.

## Additional Tips

---

- **Use blocks for critical changes**: Use block syntax to enable rollbacks and output data for critical changes.
- **Check and validate**: Use `--check` and `--diff` to validate changes also while running the playbooks on Semaphore before applying them.
82 changes: 42 additions & 40 deletions ansible/bios.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2022 Dell Inc, or its subsidiaries.
---

- name:
- name: Run BIOS Configuration
hosts: hostbmcs
become: yes
become: true
tasks:
- name: Get Firmware Inventory
community.general.redfish_info:
Expand All @@ -16,7 +15,8 @@
register: result

- name: Debug print first firmware entry version
ansible.builtin.debug: var=result.redfish_facts.firmware.entries[0].Version
ansible.builtin.debug:
var: result.redfish_facts.firmware.entries[0].Version

- name: Get BIOS attributes
community.general.redfish_info:
Expand All @@ -28,64 +28,66 @@
register: result

- name: Debug print bios serial number
ansible.builtin.debug: msg={{ result.redfish_facts.bios_attribute.entries[0][1].SerialNumber | default(result.redfish_facts.bios_attribute.entries[0][1].SystemServiceTag) }}

ansible.builtin.debug:
msg: >
{{ result.redfish_facts.bios_attribute.entries[0][1].SerialNumber
| default(result.redfish_facts.bios_attribute.entries[0][1].SystemServiceTag) }}
# TODO: configre BIOS to be always on ( see lab/hardware/dh123) and any virtualization or hyper threading settings we might need

- name: Debug print bios attributes
ansible.builtin.debug: msg={{ result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer }}
ansible.builtin.debug:
msg: "{{ result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer }}"
when: result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer is defined

# Updating Bios attributes in host BMCs
- name: Set BIOS attributes
community.general.redfish_config:
category: Systems
resource_id: "{{ resource_id }}"
command: SetBiosAttributes
bios_attributes: "{{ bios_attributes }}"
baseuri: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
category: Systems
resource_id: "{{ resource_id }}"
command: SetBiosAttributes
bios_attributes: "{{ bios_attributes }}"
baseuri: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
register: bios_attribute

# DELL iDRAC ONLY: Updating BIOS settings requires creating a configuration job
# to schedule the BIOS update, so comment out below for non-Dell systems.

- name: Create BIOS configuration job (schedule BIOS setting update)
when:
- result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer is defined
- result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer == "Dell Inc."
when:
- result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer is defined
- result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer == "Dell Inc."
- bios_attribute.changed
community.general.idrac_redfish_command:
category: Systems
command: CreateBiosConfigJob
baseuri: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
category: Systems
command: CreateBiosConfigJob
baseuri: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
register: bios_config_job

- name: Reboot iDRAC systems to apply new BIOS settings
when:
- result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer is defined
- result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer == "Dell Inc."
when:
- result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer is defined
- result.redfish_facts.bios_attribute.entries[0][1].SystemManufacturer == "Dell Inc."
- bios_config_job.changed
community.general.redfish_command:
category: Systems
command: PowerReboot
resource_id: "{{ resource_id }}"
baseuri: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
category: Systems
command: PowerReboot
resource_id: "{{ resource_id }}"
baseuri: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"

# TODO: Merge two reboot tasks into one. find identifier for iLO in redfish bios attributes
# TODO: Merge two reboot tasks into one. find identifier for iLO in redfish bios attributes
- name: Reboot iLO systems to apply new BIOS settings
when:
when:
- bios_attribute.changed
- inventory_hostname == 'dh2bmc' or inventory_hostname == 'dh3bmc'
community.general.redfish_command:
category: Systems
command: PowerReboot
resource_id: "{{ resource_id }}"
baseuri: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
category: Systems
command: PowerReboot
resource_id: "{{ resource_id }}"
baseuri: "{{ ansible_host }}"
username: "{{ ansible_user }}"
password: "{{ ansible_password }}"
44 changes: 22 additions & 22 deletions ansible/f5certs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
ssl_key_location: "/etc/letsencrypt/live/{{domain_name}}/privkey.pem"

tasks:
- name: Setup provider
ansible.builtin.set_fact:
provider:
server: "{{ ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
server_port: "{{ server_port }}"
no_f5_teem: yes
validate_certs: "no"
- name: Setup provider
ansible.builtin.set_fact:
provider:
server: "{{ ansible_host }}"
user: "{{ ansible_user }}"
password: "{{ ansible_password }}"
server_port: "{{ server_port }}"
no_f5_teem: true
validate_certs: "no"

#SSL Upload and Modification of VIP to use New Certificate
- name: Upload New SSL cert upload
f5networks.f5_modules.bigip_ssl_certificate:
provider: "{{ provider }}"
name: "{{ cert_list_name }}"
content: "{{ lookup('file', ssl_cert_location ) }}"
delegate_to: localhost
# SSL Upload and Modification of VIP to use New Certificate
- name: Upload New SSL cert upload
f5networks.f5_modules.bigip_ssl_certificate:
provider: "{{ provider }}"
name: "{{ cert_list_name }}"
content: "{{ lookup('file', ssl_cert_location) }}"
delegate_to: localhost

- name: Upload New SSL key upload
f5networks.f5_modules.bigip_ssl_key:
provider: "{{ provider }}"
name: "{{ cert_list_name }}"
content: "{{ lookup('file', ssl_key_location ) }}"
delegate_to: localhost
- name: Upload New SSL key upload
f5networks.f5_modules.bigip_ssl_key:
provider: "{{ provider }}"
name: "{{ cert_list_name }}"
content: "{{ lookup('file', ssl_key_location) }}"
delegate_to: localhost
Loading
Loading