Making Ansible Roles¶
Step 1: Make A Github Repo¶
go to git hub and login as edmonds commerce
click on plus and new repo
call it ansible-role-xxxxx
Step : Clone the empty repo into your roles directory¶
[simon@localhost ansible-project]$ cd roles/
[simon@localhost roles]$ git clone git@github.com:edmondscommerce/ansible-role-fedora.git
[simon@localhost roles]$ mv ansible-role-fedora/ edmondscommerce.fedora
Step : Init The Repo With Ansible Galaxy¶
cd roles/edmondscommerce.fedora
ansible-galaxy init . --force
Step : Edit the Meta meta/main.yml¶
For example:
galaxy_info:
author: edmondscommerce
description: Basic fedora setup
company: Edmonds Commerce
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
min_ansible_version: 2.0
role_name: fedora
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:
#
# platforms is a list of platforms, and each platform has a name and a list of versions.
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
platforms:
- name: Fedora
versions:
- 29
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
Step : Edit the README.md File¶
For Example:
Role Name
=========
Basic config for Fedora
Requirements
------------
N/A
Role Variables
--------------
To Do
Dependencies
------------
N/A
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: edmondscommerce.fedora }
License
-------
BSD
Author Information
------------------
[Edmonds Commerce](https://www.edmondscommerce.co.uk) are a UK based PHP development agency specialising in E-Commerce and Magento.
https://www.edmondscommerce.co.uk
Step : Commit and push the work so far.¶
cd roles/edmondscommerce.fedora
git add -A
git commit -m "initial commit of this new role"
git push origin master
Step : Now Work on the Role Tasks,Variables,Defaults and Templates etc¶
This beyond the scope these docs. This is where you will make the role actually do something you need it to.
For further reading check out:
- https://www.learnitguide.net/2018/02/ansible-roles-explained-with-examples.html
- https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html
Step : Add it to your requirements.yml file¶
- name: edmondscommerce.fedora
src: git@github.com:edmondscommerce/ansible-role-fedora.git
scm: git
version: master
Step : Run the install roles playbook¶
ansible-playbook plays/ansible-dev/playbook-install-roles.yml