Ansible-Nginx-Cluster/roles/nginx_cluster/tasks/main.yml

86 lines
2.1 KiB
YAML
Raw Normal View History

2023-01-18 14:42:02 -07:00
---
# file: roles/nginx_cluster/tasks/main.yml
- name: Install EPEL RPM
package:
name: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm"
state: present
disable_gpg_check: True
when: ansible_distribution == 'RedHat' or ansible_distribution == 'AlmaLinux' or ansible_distribution == 'Rocky'
- name: Install prereq packages
package:
name:
- nginx
- php
- lsyncd
state: latest
- name: Create temp directory
file:
path: "{{ nginx_cluster_temp_dir }}"
state: directory
owner: "{{ nginx_cluster_user }}"
group: "{{ nginx_cluster_user }}"
mode: '700'
- name: Create sync directory
file:
path: "{{ nginx_cluser_sync_site_dir }}"
state: directory
owner: "nginx"
group: "nginx"
mode: '755'
- name: Generate ssh keypair for cluster communication
user:
name: "{{ nginx_cluster_user }}"
generate_ssh_key: yes
ssh_key_type: ed25519
ssh_key_bits: 4096
ssh_key_file: "{{ nginx_cluster_private_key }}"
ssh_key_passphrase: ""
force: no
- name: Get the public key
slurp:
src: "{{ nginx_cluster_private_key }}.pub"
register: slurped_pub_key
- name: Decode the pub key and store as fact
set_fact:
nginx_cluster_public_key: "{{ slurped_pub_key.content | b64decode }}"
- name: Setup access for other servers
include_tasks: setup-server.yml
loop: "{{ groups['nginx_cluster']|difference([inventory_hostname]) }}"
loop_control:
extended: yes
- name: Create variable of other members IPs to be included into the cluster
set_fact: nodelist={%for host in groups['nginx_cluster']|difference([inventory_hostname])%}"{{hostvars[host].ansible_host}}"{% if not loop.last %},{% endif %}{% endfor %}
- name: Update lsyncd config
template:
src: "lsynd.conf.j2"
dest: "/etc/lsyncd.conf"
notify: Restart lsyncd
- name: Start and enable lsyncd
service:
name: lsyncd
state: started
enabled: yes
- name: Start and enable nginx
service:
name: nginx
state: started
2023-01-23 06:20:29 -07:00
enabled: yes
2023-01-18 14:42:02 -07:00
- name: Start and enable php
service:
name: php-fpm
state: started
2023-01-23 06:20:29 -07:00
enabled: yes