Skip to content

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

creating new a role

Step : Clone the empty repo into your roles directory

[simon@localhost ansible-project]$ cd roles/
[simon@localhost roles]$ git clone
[simon@localhost roles]$ mv ansible-role-fedora/ edmondscommerce.fedora

Step : Init The Repo With Ansible Galaxy

cd roles/edmondscommerce.fedora
ansible-galaxy init . --force
Then you should see that it has reated some files and folders

Ansible galaxy init

Step : Edit the Meta meta/main.yml

For example:

  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:

  # 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.

  # 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
    - name: Fedora
        - 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 File

For Example:

Role Name

Basic config for Fedora 



Role Variables

To Do



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
         - { role: edmondscommerce.fedora }



Author Information

[Edmonds Commerce]( are a UK based PHP development agency specialising in E-Commerce and Magento.

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:

Step : Add it to your requirements.yml file

 - name: edmondscommerce.fedora
  scm: git
  version: master

Step : Run the install roles playbook

ansible-playbook plays/ansible-dev/playbook-install-roles.yml