From 895ee00f6cf849ab6defa3d3a405daa00339bd63 Mon Sep 17 00:00:00 2001 From: DeadNews Date: Sun, 30 Jun 2024 03:23:45 +0800 Subject: [PATCH] feat(system_info): add role (#37) --- roles/aptup/molecule/aptup/converge.yml | 12 +++++------ .../aptup/molecule/aptup_vagrant/converge.yml | 13 ++++++------ roles/docker/molecule/docker/converge.yml | 16 +++++++-------- .../molecule/docker_vagrant/converge.yml | 16 +++++++-------- .../molecule/docker_compose/converge.yml | 4 ++++ roles/reboot/README.md | 8 ++++++++ roles/system_info/README.md | 11 ++++++++++ roles/system_info/meta/main.yml | 6 ++++++ roles/system_info/tasks/main.yml | 20 +++++++++++++++++++ .../wireguard/molecule/wireguard/converge.yml | 4 ++++ 10 files changed, 78 insertions(+), 32 deletions(-) create mode 100644 roles/system_info/README.md create mode 100644 roles/system_info/meta/main.yml create mode 100644 roles/system_info/tasks/main.yml diff --git a/roles/aptup/molecule/aptup/converge.yml b/roles/aptup/molecule/aptup/converge.yml index 89c06921..c41358b3 100644 --- a/roles/aptup/molecule/aptup/converge.yml +++ b/roles/aptup/molecule/aptup/converge.yml @@ -3,10 +3,8 @@ hosts: all become: true - tasks: - - name: Test role - ansible.builtin.import_role: - name: deadnews.util.aptup - vars: - aptup_next_release: false - aptup_show_stdout: true + roles: + - role: deadnews.util.system_info + - role: deadnews.util.aptup + aptup_next_release: false + aptup_show_stdout: true diff --git a/roles/aptup/molecule/aptup_vagrant/converge.yml b/roles/aptup/molecule/aptup_vagrant/converge.yml index 4fef4d35..be302d53 100644 --- a/roles/aptup/molecule/aptup_vagrant/converge.yml +++ b/roles/aptup/molecule/aptup_vagrant/converge.yml @@ -3,10 +3,9 @@ hosts: all become: true - tasks: - - name: Test role - ansible.builtin.import_role: - name: deadnews.util.aptup - vars: - aptup_next_release: true - aptup_next_release_update_grub: false + roles: + - role: deadnews.util.system_info + - role: deadnews.util.aptup + aptup_next_release: true + aptup_show_stdout: true + aptup_next_release_update_grub: false diff --git a/roles/docker/molecule/docker/converge.yml b/roles/docker/molecule/docker/converge.yml index f3971268..d8bd90f6 100644 --- a/roles/docker/molecule/docker/converge.yml +++ b/roles/docker/molecule/docker/converge.yml @@ -3,12 +3,10 @@ hosts: all become: true - tasks: - - name: Install Docker - ansible.builtin.import_role: - name: deadnews.util.docker - vars: - docker_rootless: true - docker_config: files/config.json - docker_config_daemon: files/daemon.json - docker_config_systemd: templates/proxy.conf.j2 + roles: + - role: deadnews.util.system_info + - role: deadnews.util.docker + docker_rootless: true + docker_config: files/config.json + docker_config_daemon: files/daemon.json + docker_config_systemd: templates/proxy.conf.j2 diff --git a/roles/docker/molecule/docker_vagrant/converge.yml b/roles/docker/molecule/docker_vagrant/converge.yml index 962e4b98..ad7c5c50 100644 --- a/roles/docker/molecule/docker_vagrant/converge.yml +++ b/roles/docker/molecule/docker_vagrant/converge.yml @@ -3,12 +3,10 @@ hosts: all become: true - tasks: - - name: Test role - ansible.builtin.import_role: - name: deadnews.util.docker - vars: - docker_rootless: true - docker_rootless_expose_privileged_ports: true - docker_cleanup_scheduled: true - docker_hold_packages: true + roles: + - role: deadnews.util.system_info + - role: deadnews.util.docker + docker_rootless: true + docker_rootless_expose_privileged_ports: true + docker_cleanup_scheduled: true + docker_hold_packages: true diff --git a/roles/docker_compose/molecule/docker_compose/converge.yml b/roles/docker_compose/molecule/docker_compose/converge.yml index f394cd3b..2da91cc9 100644 --- a/roles/docker_compose/molecule/docker_compose/converge.yml +++ b/roles/docker_compose/molecule/docker_compose/converge.yml @@ -4,6 +4,10 @@ become: true tasks: + - name: Show system info + ansible.builtin.import_role: + name: deadnews.util.system_info + - name: Install Docker ansible.builtin.import_role: name: deadnews.util.docker diff --git a/roles/reboot/README.md b/roles/reboot/README.md index e6592e6f..84cc4c41 100644 --- a/roles/reboot/README.md +++ b/roles/reboot/README.md @@ -1,3 +1,11 @@ # deadnews.util.reboot > Reboot machine if nedeed + +## Example Playbook + +```yaml +- hosts: servers + roles: + - role: deadnews.util.reboot +``` diff --git a/roles/system_info/README.md b/roles/system_info/README.md new file mode 100644 index 00000000..4c907088 --- /dev/null +++ b/roles/system_info/README.md @@ -0,0 +1,11 @@ +# deadnews.util.system_info + +> Show system info + +## Example Playbook + +```yaml +- hosts: servers + roles: + - role: deadnews.util.system_info +``` diff --git a/roles/system_info/meta/main.yml b/roles/system_info/meta/main.yml new file mode 100644 index 00000000..aa532773 --- /dev/null +++ b/roles/system_info/meta/main.yml @@ -0,0 +1,6 @@ +--- +galaxy_info: + author: DeadNews + description: Show system info + license: MIT + min_ansible_version: 2.16.0 diff --git a/roles/system_info/tasks/main.yml b/roles/system_info/tasks/main.yml new file mode 100644 index 00000000..9792dd21 --- /dev/null +++ b/roles/system_info/tasks/main.yml @@ -0,0 +1,20 @@ +--- +# Show system info + +- name: Show system info (can be cashed) + ansible.builtin.debug: + msg: | + Hostname: {{ ansible_hostname }} + System: {{ ansible_distribution }} {{ ansible_distribution_version }} {{ ansible_distribution_release }} + Kernel: {{ ansible_kernel }} + Python: {{ ansible_python_version }} + Product: {{ ansible_product_name }} + CPUs: {{ ansible_processor_count }} × {{ ansible_processor[2] }} + Cores: {{ ansible_processor_nproc }} cores, {{ ansible_processor_nproc * ansible_processor_threads_per_core }} threads + Memory: {{ (ansible_memtotal_mb / 1024) | round(2) }} GiB + Uptime: {{ + (ansible_uptime_seconds // 86400) | string + 'd ' + + ((ansible_uptime_seconds // 3600) % 24) | string + 'h ' + + ((ansible_uptime_seconds // 60) % 60) | string + 'm ' + + (ansible_uptime_seconds % 60) | string + 's' + }} diff --git a/roles/wireguard/molecule/wireguard/converge.yml b/roles/wireguard/molecule/wireguard/converge.yml index 445da0c1..6e8aecd9 100644 --- a/roles/wireguard/molecule/wireguard/converge.yml +++ b/roles/wireguard/molecule/wireguard/converge.yml @@ -10,6 +10,10 @@ wireguard_publickey_peer: iEuV0dLE9OYfZzoKYrHZBK6Hzr/8dn1aovDuUrt9/g8= # gitleaks:allow tasks: + - name: Show system info + ansible.builtin.include_role: + name: deadnews.util.system_info + - name: Install iptables ansible.builtin.apt: name: iptables