Bash to Playbook

Install and Setup Tomcat

Turn the following Script into a Playbook

yum install java-1.7.0-openjdk-devel
sudo groupadd tomcat
sudo useradd -G tomcat tomcat
wget -P /opt http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.61/bin/apache-tomcat-7.0.61.tar.gz
tar -xvf /opt/apache-tomcat-7.0.61.tar.gz
ln -s /opt/apache-tomcat-7.0.61 /usr/share/tomcat
chown -R tomcat:tomcat /usr/share/tomcat
sudo service tomcat7 start
Solution
- hosts: localhost
  gather_facts: no
  tasks:
    - name: Install Java 1.7
      yum:
        name: java-1.7.0-openjdk
        state: present
    - name: add group tomcat
      group:
        name: tomcat
    - name: add user tomcat
      user:
        name: tomcat
        group: tomcat
        home: /usr/share/tomcat
        createhome: no
      become: True
      become_method: sudo
    - name: Download Tomcat
      get_url:
        url: http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.61/bin/apache-tomcat-7.0.61.tar.gz
        dest: /opt/apache-tomcat-7.0.61.tar.gz
    - name: Extract archive
      command: chdir=/usr/share /bin/tar xvf /opt/apache-tomcat-7.0.61.tar.gz -C /opt/ creates=/opt/apache-tomcat-7.0.61
    - name: symlink install directory
      file:
        src: /opt/apache-tomcat-7.0.61
        path: /usr/share/tomcat
        state: link
    - name: Change ownership of Tomcat Installation
      file:
        path: /usr/share/tomcat/
        owner: tomcat
        group: tomcat
        state: directory
        recurse: yes
    - name: Start Tomcat
      service:
        name: tomcat
        state: started
        enabled: yes