Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Ansible - Role

Back


Role


Standard Role Directory Structure

myrole/ ├── defaults/ # Default variables (lowest priority) │ └── main.yml ├── vars/ # Other variables (higher priority) │ └── main.yml ├── files/ # Static files to copy ├── templates/ # Jinja2 templates ├── tasks/ # Main list of tasks │ └── main.yml ├── handlers/ # Handlers triggered by notify │ └── main.yml ├── meta/ # Role dependencies and metadata │ └── main.yml └── README.md # Documentation (optional but recommended)


Assign playbook a role

- name: Install and configure mysql
  hosts: db-server
  roles:
    - mysql
- name: Install and configure mysql
  hosts: db-server
  roles:
    - role: mysql
      become: yes
      vars:
        mysql_user_name: db_user
  1. create roles in the playbook dir, and place all files required by the role into this dir
  2. Place the role required file in the default dir /etc/ansible/roles