1. 安装collection devsec.hardening
$ ansible-galaxy collection install devsec.hardening
2. 查看role
$ tree -d /home/rocky/.ansible/collections/ansible_collections/devsec/hardening
3. 剧本文件site.yml
$ cat site.yml
---
- hosts: local
gather_facts: yes
become: yes
collections:
- devsec.hardening
tasks:
- import_role:
name: os_hardening
4. 执行剧本
$ ansible-playbook -i /etc/ansible/hosts site.yml -k -e 'ansible_user=rocky'