in Ansible by

What are 

ansible roles examples

1 Answer

0 votes
Utilizing Roles in Playbook

This is the code of the playbook we have written for demo purpose. This code is of the playbook vivek_orchestrate.yml. We have defined the hosts: tomcat-node and called the two roles – install-tomcat and start-tomcat.

The problem statement is that we have a war which we need to deploy on a machine via Ansible.


- hosts: tomcat-node


   - {role: install-tomcat}

   - {role: start-tomcat}

Contents of our directory structure from where we are running the playbook.


$ ls

ansible.cfg  hosts  roles  vivek_orchestrate.retry vivek_orchestrate.yml


There is a tasks directory under each directory and it contains a main.yml. The main.yml contents of install-tomcat are −


#Install vivek artifacts



      - name: Install Tomcat artifacts

         action: >

            yum name = "demo-tomcat-1" state = present

         register: Output



      - debug:


            - "Install Tomcat artifacts task ended with message: {{Output}}"

            - "Installed Tomcat artifacts - {{Output.changed}}"

The contents of main.yml of the start tomcat are −

#Start Tomcat          



      - name: Start Tomcat

      command: <path of tomcat>/bin/"

      register: output

      become: true



      - debug:


            - "Start Tomcat task ended with message: {{output}}"

            - "Tomcat started - {{output.changed}}"

Related questions

0 votes
asked Nov 5, 2019 in Ansible by Robin
0 votes
asked Nov 27, 2019 in DevOps by rajeshsharma
0 votes
asked Jul 30, 2021 in Ansible by DavidAnderson