diff --git a/tests.yml b/plays/generate_documentation.yml similarity index 81% rename from tests.yml rename to plays/generate_documentation.yml index 9b61052c..ce7a3859 100755 --- a/tests.yml +++ b/plays/generate_documentation.yml @@ -1,7 +1,7 @@ #!/usr/bin/env ansible-playbook --- # Document servers -- hosts: zamok.adm.crans.org # test only on voyager for now +- hosts: server vars: moinmoin_user: "{{ vault_moinmoin_user }}" moinmoin_password: "{{ vault_moinmoin_password }}" diff --git a/roles/moinmoin-gendoc/library/dmidecode.py b/roles/moinmoin-gendoc/library/dmidecode.py new file mode 100644 index 00000000..2ffc403a --- /dev/null +++ b/roles/moinmoin-gendoc/library/dmidecode.py @@ -0,0 +1,68 @@ +#!/usr/bin/python + +# Written By - Rishabh Das +# Modified By - Alexandre Iooss +# +# This program is a free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 2 of the license, or(at your option) any +# later version. See http://www.gnu.org/copyleft/gpl.html for the full text of +# the license. + +############################################################################## + +DOCUMENTATION = ''' +--- +module: dmidecode +version_added: "0.1" +short_description: Get dmidecode information for your infrastructure. +description: + - Get the dmidecode information of your infrastructure. +''' + +EXAMPLES = ''' +# dmidecode module takes in 'save' as a paramter. If set True, +# this stores the dmidecode JSON output on the target machine. +# This by default is set to False. + +# Usage Examples - + +- name: Get dmidecode data + action: dmidecode + +''' + +import dmidecode +import json + +from ansible.module_utils.basic import AnsibleModule + + +def decode_dict(data): + data_type = type(data) + if data == None: return "" + if data_type == bytes: return data.decode() + if data_type in (str, int, bool): return str(data) + if data_type == dict: data = data.items() + return data_type(map(decode_dict, data)) + +def run_module(): + module = AnsibleModule( + argument_spec = {} + ) + dmi_data = decode_dict({ + 'bios': dmidecode.bios(), + 'processor': dmidecode.processor(), + 'system': dmidecode.system(), + 'memory': dmidecode.memory(), + 'slot': dmidecode.slot(), + }) + module.exit_json(changed=True, ansible_facts=dmi_data) + + +def main(): + run_module() + + +if __name__ == '__main__': + main() diff --git a/roles/moinmoin-gendoc/tasks/main.yml b/roles/moinmoin-gendoc/tasks/main.yml index 6bbc105f..0c5fb53e 100644 --- a/roles/moinmoin-gendoc/tasks/main.yml +++ b/roles/moinmoin-gendoc/tasks/main.yml @@ -1,4 +1,15 @@ --- +- name: Install python3-dmidecode + apt: + update_cache: true + name: python3-dmidecode + register: apt_result + retries: 3 + until: apt_result is succeeded + +- name: get dmidecode facts + dmidecode: {} + - name: "Create wiki page documenting {{ ansible_hostname }} (physical)" when: ansible_system_vendor != 'QEMU' moinmoin_page: diff --git a/roles/moinmoin-gendoc/templates/server.j2 b/roles/moinmoin-gendoc/templates/server.j2 index 701acee9..ffc599e4 100644 --- a/roles/moinmoin-gendoc/templates/server.j2 +++ b/roles/moinmoin-gendoc/templates/server.j2 @@ -14,33 +14,40 @@ '''Domaine''' : {{ ansible_domain }} -'''CPU''' : -{{ ansible_processor_count }} processeur(s) -avec {{ ansible_processor_cores }} cœur(s) -divisé(s) en {{ ansible_processor_threads_per_core }} thread(s). +=== Processeur === -'''Mémoire''' : -{{ (ansible_memory_mb.real.total/1024)|round(1) }} GiB de mémoire RAM -et {{ (ansible_memory_mb.swap.total/1024)|round(1) }} GiB de SWAP. - -=== Stockage === - -|| Point de montage || Taille || Disque || -{% for m in ansible_mounts %} -{% if m.fstype == 'ext4' and 'size_total' in m %} -|| {{ m.mount }} || {{ m.size_total|human_readable(unit='G') }} || {{ m.device }} || +|| '''Socket''' || '''Nombre de cœur(s)''' || '''Nombre de thread(s)''' || '''Modèle''' || +{% for m in processor.values() %} +{% if m.data["Asset Tag"] %} +|| {{ m.data["Socket Designation"] }} || {{ m.data["Core Count"] }} || {{ m.data["Thread Count"] }} || {{ m.data["Version"] }} || {% endif %} {% endfor %} -=== Interfaces réseau === +=== Mémoire vive === -|| Device || IPv4 || IPv6 || MAC || -{% for i in ansible_interfaces %} -{% set interface = vars["ansible_" + i] %} -{% if interface.active and interface.type == 'ether' and 'ipv4' in interface %} -|| {{ interface.device }} || {{ interface.ipv4.address }} || {# No newline #} -{% for ip in interface.ipv6 %}{{ ip.address }} {% endfor %} || {# No newline #} -{{ interface.macaddress }} || +{{ (ansible_memory_mb.real.total/1024)|round(1) }} GiB de mémoire RAM +et {{ (ansible_memory_mb.swap.total/1024)|round(1) }} GiB de SWAP. + +|| '''Emplacement''' || '''Taille''' || '''Vitesse''' || '''Caractéristiques''' || '''Modèle''' || +{% for m in memory.values() %} +{% if m.data.Locator is defined and m.data.Size %} +|| {{ m.data["Locator"] }} || {{ m.data["Size"] }} || {{ m.data["Speed"] }} || {{ m.data["Type Detail"] | join(' ') }} || {{ m.data["Manufacturer"] }} {{ m.data["Part Number"] }} || +{% endif %} +{% endfor %} + +=== Cartes PCI === + +|| '''Emplacement''' || '''Taille du bus''' || +{% for m in slot.values() %} +|| {{ m.data["Designation"] }} || {{ m.data["Type:SlotType"] }} {{ m.data["Type:SlotBusWidth"] }} || +{% endfor %} + +=== Stockage === + +|| '''Point de montage''' || '''Taille''' || '''Disque''' || +{% for m in ansible_mounts %} +{% if m.fstype == 'ext4' and 'size_total' in m %} +|| {{ m.mount }} || {{ m.size_total|human_readable(unit='G') }} || {{ m.device }} || {% endif %} {% endfor %} @@ -53,5 +60,19 @@ et {{ (ansible_memory_mb.swap.total/1024)|round(1) }} GiB de SWAP. {{ ansible_kernel }} '''BIOS installé''' : -{{ ansible_bios_version }} datant du {{ ansible_bios_date }} +{%- for b in bios.values() %} +{{ b.data["Vendor"] }} {{ b.data["Version"] }} {{ b.data["BIOS Revision"] }} ({{ b.data["Release Date"] }}) +{%- if b.data["Characteristic x2"]["UEFI is supported"] == "True" %}, UEFI{% endif %} +{% endfor %} +=== Interfaces réseau === + +|| '''Interface''' || '''IPv4''' || '''IPv6''' || '''MAC''' || +{% for i in ansible_interfaces %} +{% set interface = vars["ansible_" + i] %} +{% if interface.active and interface.type == 'ether' and 'ipv4' in interface %} +|| {{ interface.device }} || {{ interface.ipv4.address }} || {# No newline #} +{% for ip in interface.ipv6 %}{{ ip.address }} {% endfor %} || {# No newline #} +{{ interface.macaddress }} || +{% endif %} +{% endfor %}