-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Components
If you want to add your own roles to the project, follow these steps to create and integrate a new role.
If you want to add your own roles or red team components to the project, follow these steps to create and integrate a new role:
-
Create the Role Structure
Use the following directory structure as a template for your role. Replaceyour_servicewith the name of your role:roles/ └── your_service/ ├── tasks/ │ └── main.yaml ├── handlers/ │ └── main.yaml ├── vars/ │ └── main.yaml └── templates/ └── example_config.j2 -
Define Tasks
Inroles/your_service/tasks/main.yaml, define the tasks required to configure your service. Example:--- - name: Install necessary packages apt: name: "{{ your_service_packages }}" state: present become: yes - name: Deploy configuration file template: src: your_config.j2 dest: /opt/your_service/config.yaml owner: root group: root mode: '0644'
-
Set Default Variables
Useroles/your_service/defaults/main.yamlto set default variables for your role:your_service_packages: - nginx - curl - python3
-
Define Role Variables
Customize variables inroles/your_service/vars/main.yaml. These will override defaults if specified:--- your_service_config_path: /opt/your_service/config.yaml
-
Add Templates or Files
Place configuration templates in thetemplates/directory. For example,roles/your_service/templates/example_config.j2:server: host: "{{ ansible_host }}" port: 8080 logging: level: info
-
Include Handlers
Inroles/your_service/handlers/main.yaml, define any handlers for tasks that require reloading services:--- - name: Restart your_service service: name: your_service state: restarted
-
Add your Host to the Inventory The next step is to define your remote machine in the
inventory.yaml. For Ansible to work, you need to specify the required connection details like shown below:all: hosts: your_service_host: ansible_host: 192.168.0.67 ansible_user: slrt ansible_ssh_private_key_file: /home/<local_user>/.ssh/slrt_deployment_id ansible_become: true ansible_sudo_pass: <password>
-
Integrate the Role in the Playbook
Add the role to your playbook (deployment-your_service.yaml):--- - hosts: your_service_host roles: - your_service
-
Test the Role
Run your playbook to ensure your new role is working as expected:ansible-playbook -i inventory.yaml deployment-your_service.yaml