Installing tomcat on ubuntu
- Remaining steps
- correcting the extract
- setting permissions
- creating service file
- restarting service
sudo chown -R tomcat: /opt/tomcat
sudo chmod +x /opt/tomcat/bin/*.sh
-
To run raw linux commands we have modules like command, shell etc. These modules are not idempotent i.e. they run during every ansible execution
-
Ansible handlers
- Ansible playbook is collection of tasks and handlers. Ansible Handler is also a module like task but it runs when some task calls it that to when changed.
---
- name: install tomcat on ubuntu server
hosts: appservers
become: yes
tasks:
- name: update packages and install java
ansible.builtin.apt:
name: "{{ java_package_name }}"
update_cache: yes
state: present
- name: Ensure group tomcat exists
ansible.builtin.group:
name: "{{ tomcat_system_groupname }}"
state: present
- name: create tomcat user
ansible.builtin.user:
name: "{{ tomcat_system_username }}"
system: yes
create_home: yes
group: "{{ tomcat_system_groupname }}"
home: "{{ tomcat_homedir }}"
shell: "{{ tomcat_shell }}"
- name: download tomcat
ansible.builtin.unarchive:
src: "{{ tomcat_download_url }}"
dest: "{{ tomcat_homedir }}"
remote_src: yes
owner: "{{ tomcat_system_username }}"
group: "{{ tomcat_system_groupname }}"
extra_opts:
- --strip-components=1
notify:
- make scripts excutable
handlers:
- name: make scripts executable
command: chmod +x /opt/tomcat/bin/*.sh
- The other version is get all the script using ansible module find
---
- name: install tomcat on ubuntu server
hosts: appservers
become: yes
tasks:
- name: update packages and install java
ansible.builtin.apt:
name: "{{ java_package_name }}"
update_cache: yes
state: present
- name: Ensure group tomcat exists
ansible.builtin.group:
name: "{{ tomcat_system_groupname }}"
state: present
- name: create tomcat user
ansible.builtin.user:
name: "{{ tomcat_system_username }}"
system: yes
create_home: yes
group: "{{ tomcat_system_groupname }}"
home: "{{ tomcat_homedir }}"
shell: "{{ tomcat_shell }}"
- name: download tomcat
ansible.builtin.unarchive:
src: "{{ tomcat_download_url }}"
dest: "{{ tomcat_homedir }}"
remote_src: yes
owner: "{{ tomcat_system_username }}"
group: "{{ tomcat_system_groupname }}"
extra_opts:
- --strip-components=1
- name: Find script files
ansible.builtin.find:
paths: /opt/tomcat/bin/
patterns: '*.sh'
register: script_files
- name: print files
ansible.builtin.debug:
var: script_files