forked from CCCHH/ansible-infra
95 lines
3.4 KiB
YAML
95 lines
3.4 KiB
YAML
---
|
|
# Copyright (C) 2017 Maciej Delmanowski <drybjed@gmail.com>
|
|
# Copyright (C) 2017 DebOps <https://debops.org/>
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
- name: Import custom Ansible plugins
|
|
ansible.builtin.import_role:
|
|
name: 'ansible_plugins'
|
|
|
|
- name: Import DebOps global handlers
|
|
ansible.builtin.import_role:
|
|
name: 'global_handlers'
|
|
|
|
- name: Import DebOps secret role
|
|
ansible.builtin.import_role:
|
|
name: 'secret'
|
|
|
|
- name: Install required packages
|
|
ansible.builtin.package:
|
|
name: '{{ q("flattened", (sysfs__base_packages
|
|
+ sysfs__packages)) }}'
|
|
state: 'present'
|
|
register: sysfs__register_packages
|
|
until: sysfs__register_packages is succeeded
|
|
when: sysfs__enabled | bool
|
|
|
|
- name: Check if the dependent configuration exists
|
|
ansible.builtin.stat:
|
|
path: '{{ secret + "/sysfs/dependent_config/" + inventory_hostname + "/attributes.json" }}'
|
|
register: sysfs__register_dependent_attributes_file
|
|
become: False
|
|
delegate_to: 'localhost'
|
|
when: (sysfs__enabled | bool and ansible_local | d() and ansible_local.sysfs | d() and
|
|
(ansible_local.sysfs.configured | d()) | bool)
|
|
|
|
- name: Load the dependent configuration from Ansible Controller
|
|
ansible.builtin.slurp:
|
|
src: '{{ secret + "/sysfs/dependent_config/" + inventory_hostname + "/attributes.json" }}'
|
|
register: sysfs__register_dependent_attributes
|
|
become: False
|
|
delegate_to: 'localhost'
|
|
when: (sysfs__enabled | bool and ansible_local | d() and ansible_local.sysfs | d() and
|
|
(ansible_local.sysfs.configured | d()) | bool and
|
|
sysfs__register_dependent_attributes_file.stat.exists | bool)
|
|
|
|
- name: Remove sysfs configuration files if requested
|
|
ansible.builtin.file:
|
|
path: '/etc/sysfs.d/{{ item.filename | d(item.name | replace("/", "_")) }}.conf'
|
|
state: 'absent'
|
|
with_items: '{{ sysfs__combined_attributes | debops.debops.parse_kv_items }}'
|
|
notify: [ 'Restart sysfsutils' ]
|
|
when: (sysfs__enabled | bool and item.name | d() and
|
|
item.state | d('present') == 'absent')
|
|
|
|
- name: Generate sysfs configuration files
|
|
ansible.builtin.template:
|
|
src: 'etc/sysfs.d/attribute.conf.j2'
|
|
dest: '/etc/sysfs.d/{{ item.filename | d(item.name | replace("/", "_")) }}.conf'
|
|
owner: 'root'
|
|
group: 'root'
|
|
mode: '0644'
|
|
with_items: '{{ sysfs__combined_attributes | debops.debops.parse_kv_items }}'
|
|
notify: [ 'Restart sysfsutils' ]
|
|
when: (sysfs__enabled | bool and item.name | d() and
|
|
item.state | d('present') not in ['defined', 'absent'])
|
|
|
|
- name: Make sure that Ansible local facts directory exists
|
|
ansible.builtin.file:
|
|
path: '/etc/ansible/facts.d'
|
|
state: 'directory'
|
|
owner: 'root'
|
|
group: 'root'
|
|
mode: '0755'
|
|
|
|
- name: Save sysfs local facts
|
|
ansible.builtin.template:
|
|
src: 'etc/ansible/facts.d/sysfs.fact.j2'
|
|
dest: '/etc/ansible/facts.d/sysfs.fact'
|
|
owner: 'root'
|
|
group: 'root'
|
|
mode: '0755'
|
|
notify: [ 'Refresh host facts' ]
|
|
tags: [ 'meta::facts' ]
|
|
|
|
- name: Update Ansible facts if they were modified
|
|
ansible.builtin.meta: 'flush_handlers'
|
|
|
|
- name: Save dependent configuration on Ansible Controller
|
|
ansible.builtin.template:
|
|
src: 'secret/sysfs/dependent_config/inventory_hostname/attributes.json.j2'
|
|
dest: '{{ secret + "/sysfs/dependent_config/" + inventory_hostname + "/attributes.json" }}'
|
|
mode: '0644'
|
|
become: False
|
|
delegate_to: 'localhost'
|
|
when: sysfs__enabled | bool
|