--- # 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 - name: Start and enable php service: name: php-fpm state: started