ansible-roles/tomcat-instance/tasks/user.yml

80 lines
2.3 KiB
YAML
Raw Normal View History

2017-01-03 12:41:19 +01:00
---
- fail:
msg: "You must provide a value for the 'tomcat_instance_port' variable."
when: tomcat_instance_port is not defined or tomcat_instance_port == ''
- name: "Test if uid '{{ tomcat_instance_port }}' exists"
command: 'id -un -- "{{ tomcat_instance_port }}"'
register: get_login_from_id
failed_when: False
changed_when: False
check_mode: no
- name: "Fail if uid already exists for another user"
fail:
msg: "Uid '{{ tomcat_instance_port }}' is already used by '{{ get_login_from_id.stdout }}'. You must change uid for '{{ tomcat_instance_name }}'"
when:
- get_login_from_id.rc == 0
- get_login_from_id.stdout != tomcat_instance_name
2017-01-03 12:41:19 +01:00
- name: Create group instance
group:
2019-05-14 13:57:31 +02:00
name: "{{ tomcat_instance_name }}"
gid: "{{ tomcat_instance_port }}"
2017-01-03 12:41:19 +01:00
- name: Create user instance
user:
name: "{{ tomcat_instance_name }}"
group: "{{ tomcat_instance_name }}"
uid: "{{ tomcat_instance_port }}"
home: "{{ tomcat_instance_root }}/{{ tomcat_instance_name }}"
shell: '/bin/bash'
createhome: no
- name: Create home dir
file:
path: "{{ tomcat_instance_root }}/{{ tomcat_instance_name }}"
state: directory
owner: "{{ tomcat_instance_name }}"
group: "{{ tomcat_instance_name }}"
mode: "u=rwx,g=rwxs,o="
2017-01-03 12:41:19 +01:00
- name: Is /etc/aliases present?
stat:
path: /etc/aliases
register: etc_aliases
2017-01-03 12:41:19 +01:00
- name: Set mail alias for user
lineinfile:
dest: '/etc/aliases'
state: present
line: "{{ tomcat_instance_name }}: {{ tomcat_instance_mail }}"
regexp: "{{ tomcat_instance_name }}:"
when: etc_aliases.stat.exists and tomcat_instance_mail is defined
2017-07-07 11:34:28 +02:00
register: tomcat_instance_mail_alias
- name: Run newaliases
command: newaliases
2019-12-31 15:34:48 +01:00
when: tomcat_instance_mail_alias is changed
2017-01-03 12:41:19 +01:00
- name: Enable sudo right
lineinfile:
dest: '/etc/sudoers.d/tomcat'
state: present
mode: "0440"
2017-01-03 12:41:19 +01:00
create: yes
line: "%{{ tomcat_instance_name }} ALL = ({{ tomcat_instance_name }}) SETENV: ALL"
validate: 'visudo -cf %s'
- name: Enable sudo right for deploy user
lineinfile:
dest: '/etc/sudoers.d/tomcat'
state: present
mode: "0440"
2017-01-03 12:41:19 +01:00
create: yes
line: "{{ tomcat_instance_deploy_user }} ALL = ({{ tomcat_instance_name }}) NOPASSWD: SETENV: ALL"
validate: 'visudo -cf %s'
when: tomcat_instance_deploy_user is defined