The requested handler 'Reload nginx' was not found

  • when I run my playbook I get an error message and the process is aborted
    ERROR! The requested handler 'Reload nginx' was not found in either the main handlers list nor in the listening handlers list
  • Include the version(s) of the relevant software tools, libraries, collections etc
 % ansible --version
ansible [core 2.15.9]
  config file = /Users/micneu/Library/Mobile Documents/com~apple~CloudDocs/ansible_project/ansible.cfg
  configured module search path = ['/usr/share/ansible']
  ansible python module location = /Users/micneu/Library/Python/3.9/lib/python/site-packages/ansible
  ansible collection location = /Users/micneu/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/micneu/Library/Python/3.9/bin/ansible
  python version = 3.9.6 (default, Mar 29 2024, 10:51:09) [Clang 15.0.0 (clang-1500.3.9.4)] (/Applications/Xcode.app/Contents/Developer/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True
  • Include relevant logs from the issue
    I don’t have any logs, if so how should I find them?
  • Set at least one tag (the experts follow the tags, so the right people will find you if you tag)
1. my directory structure
nginx-reverse-proxies
|____tasks
| |____nginx.yml
| |____nginx2.yml
| |____goip.yml
| |____sys_limit.yml
| |____update_nginx_ips_2.yml
| |____docker.yml
| |____librespeed.yml
| |____le.yml
|____.DS_Store
|____files
| |____.DS_Store
| |____goip.service
| |____allowed-domain.list
| |____update_nginx_ips_2.sh
| |____aarch64
| | |____ipify-api
| |____x86_64
| | |____ipify-api
|____templates
| |____nginx-proxy.conf.j2
| |____linux.service.j2
| |____nginx-ssl.conf.j2
| |____nginx-site.conf.j2
| |____nginx-main.conf.j2
|____handlers
| |____main.yml
|____nginx-setup.yml

in the handlers directory
I have according to my understanding

---
- name: Reload nginx
  ansible.builtin.service:
    name: "nginx.service"
    state: reloaded

- name: Restart nginx
  ansible.builtin.service:
    name: "nginx.service"
    state: restarted

- name: Reload systemd
  ansible.builtin.systemd:
    daemon_reload: true

what is wrong with my code?
nginx2.yml

---
- name: Install Nginx
  ansible.builtin.apt:
    name: nginx
    state: present

- name: Install PHP and PHP-FPM
  ansible.builtin.apt:
    name: "{{ item }}"
    state: present
  loop:
    - php-fpm
    - php-mysql  # Add any other PHP extensions you need

- name: Ensure webroot directory exists
  ansible.builtin.file:
    path: "{{ webroot_path }}"
    state: directory
    owner: root
    group: root
    mode: '0644'

- name: Create main Nginx configuration
  ansible.builtin.template:
    src: templates/nginx-main.conf.j2
    dest: /etc/nginx/sites-available/reverse-proxy.conf
    owner: root
    group: root
    mode: '0644'
  notify:
    - Restart nginx

- name: Enable main Nginx configuration
  ansible.builtin.file:
    src: /etc/nginx/sites-available/reverse-proxy.conf
    dest: /etc/nginx/sites-enabled/reverse-proxy.conf
    state: link
 notify:
   - Reload nginx

- name: Remove default Nginx configuration
  ansible.builtin.file:
    path: /etc/nginx/sites-enabled/default
    state: absent
 notify:
   - Reload nginx

- name: Create SSL configuration file
  ansible.builtin.template:
    src: templates/nginx-ssl.conf.j2
    dest: /etc/nginx/snippets/ssl-params.conf
    owner: root
    group: root
    mode: '0644'
  when: use_letsencrypt

- name: Create individual site configuration files
  ansible.builtin.template:
    src: templates/nginx-site.conf.j2
    dest: "/etc/nginx/sites-available/{{ item.name }}.conf"
    owner: root
    group: root
    mode: '0644'
  loop: "{{ site_configs }}"
  notify:
    - Reload nginx

- name: Enable individual site configurations
  ansible.builtin.file:
    src: "/etc/nginx/sites-available/{{ item.name }}.conf"
    dest: "/etc/nginx/sites-enabled/{{ item.name }}.conf"
    state: link
  loop: "{{ site_configs }}"
 notify:
   - Reload nginx


Hi Micha. Is nginx-reverse-proxies a role? Also, where is your playbook?

yes, that is a role, sorry I forgot to mention it (I’m new to the topic)

nginx-setup.yml
---
- name: Setup Nginx reverse proxy, static website, and PHP with Let's Encrypt SSL
  hosts: webserver
  gather_facts: true
  become: true
  # variablen definieren
  vars:
    use_letsencrypt: false  # Set to false to disable Let's Encrypt
    enable_https_redirect: false  # Set to false to disable HTTP to HTTPS redirect
    domains:
      - domain.tld
      - www.domain.tld
      - film.domain.tld
      - ip.domain.tld
      - speedtest.domain.tld
      - adventskalender.domain.tld
      - bilder.domain.tld
    email: www2@domain.tld
    webroot_path: /var/www/html
    site_configs:
#       - name: "app1"
#         server_name: "app1.example.com"
#         proxy_pass: "http://localhost:8081"
#         access_log: "/var/log/nginx/app1_access.log"
#         error_log: "/var/log/nginx/app1_error.log"
#         type: "proxy"  # "proxy", "static", or "php"
#         root: "/var/www/app1"  # only used if type is "static" or "php"
#         custom_include: "/etc/nginx/includes/app1_custom.conf"  # optional
#         deny_ips: []  # optional
      - name: "film"
        server_name: "film2.domain.tld"
        proxy_pass: "http://192.168.3.249:8899"
        access_log: "/var/log/nginx/film_access.log"
        error_log: "/var/log/nginx/film_error.log"
        type: "proxy"  # "proxy", "static", or "php"
        root: ""  # only used if type is "static" or "php"
        custom_include: "/etc/nginx/allowed-ips-from-domains-active[.]conf"  # optional
        deny_ips: ["all"]  # optional
#       - name: "film"
#         server_name: "film.domain.tld"
#         proxy_pass: "http://127.0.0.1:8899"
#         access_log: "/var/log/nginx/film_access.log"
#         error_log: "/var/log/nginx/film_error.log"
#         type: "proxy"  # "proxy", "static", or "php"
#         root: ""  # only used if type is "static" or "php"
#         custom_include: "/etc/nginx/allowed-ips-from-domains-active.conf"  # optional
#         deny_ips: ["all"]  # optional
      - name: "ip"
        server_name: "ip2.domain.tld"
        proxy_pass: "http://127.0.0.1:8777"
        access_log: "/var/log/nginx/ip_access.log"
        error_log: "/var/log/nginx/ip_error.log"
        type: "proxy"  # "proxy", "static", or "php"
        root: ""  # only used if type is "static" or "php"
        custom_include: ""  # optional
        deny_ips: []  # optional
      - name: "speedtest"
        server_name: "speedtest2.domain.tld"
        proxy_pass: "http://127.0.0.1:8888"
        access_log: "/var/log/nginx/speedtest_access.log"
        error_log: "/var/log/nginx/speedtest_error.log"
        type: "proxy"  # "proxy", "static", or "php"
        root: "/var/www/app2"  # only used if type is "static" or "php"
        custom_include: ""  # optional
        deny_ips: []  # optional
      - name: "adventskalender"
        server_name: "adventskalender2.domain.tld"
        proxy_pass: ""
        access_log: "/var/log/nginx/adventskalender_access.log"
        error_log: "/var/log/nginx/adventskalender_error.log"
        type: "static"  # "proxy", "static", or "php"
        root: "/var/www/adventskalender/html"  # only used if type is "static" or "php"
        custom_include: ""  # optional
        deny_ips: []  # optional
      - name: "www"
        server_name: "www2.domain.tld"
        proxy_pass: "http://127.0.0.1:8888"
        access_log: "/var/log/nginx/www_access.log"
        error_log: "/var/log/nginx/www_error.log"
        type: "static"  # "proxy", "static", or "php"
        root: "/var/www/octopress"  # only used if type is "static" or "php"
        custom_include: ""  # optional
        deny_ips: []  # optional
      - name: "bilder"
        server_name: "bilder2.domain.tld"
        proxy_pass: ""
        access_log: "/var/log/nginx/bilder_access.log"
        error_log: "/var/log/nginx/bilder_error.log"
        type: "static"  # "proxy", "static", or "php"
        root: "/var/www/bilder"  # only used if type is "static" or "php"
        custom_include: ""  # optional
        deny_ips: []  # optional
  # /variablen definieren
  tasks:
#     - name: Execute the command (set ulimit)
#       ansible.builtin.shell: ulimit -n 4096; ulimit -Hn 16384

    - name: Add a line "export SYSTEMD_EDITOR=vim" to /etc/profile
      ansible.builtin.lineinfile:
        path: /etc/profile
        line: export SYSTEMD_EDITOR=vim
        create: true
        owner: root
        group: root
        mode: '0644'

    # verzeichnisse anlegen
    - name: Ensure directories exist with correct permissions
      ansible.builtin.file:
        path: "{{ item.path }}"
        state: directory
        owner: "{{ item.owner }}"
        group: "{{ item.group }}"
        mode: "{{ item.mode }}"
      loop:
        - { path: "/var/www/adventskalender", owner: "www-data", group: "adm", mode: "0755" }
        - { path: "/var/www/octopress", owner: "www-data", group: "adm", mode: "0755" }
        - { path: "/var/www/bilder", owner: "www-data", group: "adm", mode: "0755" }
        - { path: "/etc/nginx", owner: "www-data", group: "adm", mode: "0755" }
        - { path: "/var/log/nginx", owner: "www-data", group: "adm", mode: "0755" }

    - name: Include update_nginx_ips_2
      ansible.builtin.include_tasks: tasks/update_nginx_ips_2.yml

    - name: Include goip
      ansible.builtin.include_tasks: tasks/goip.yml

    - name: Include docker
      ansible.builtin.include_tasks: tasks/docker.yml

    - name: Include docker librespeed
      ansible.builtin.include_tasks: tasks/librespeed.yml

    - name: Include nginx2
      ansible.builtin.include_tasks: tasks/nginx2.yml

    - name: Include le
      ansible.builtin.include_tasks: tasks/le.yml