I'm trying to setup a simple HTTP server on a Debian machine with the following config:
# my_role/meta/main.yml
---
allow_duplicates: no
dependencies:
- role: nginxinc.nginx
become: yes
- role: nginxinc.nginx_config
become: yes
vars:
nginx_config_debug_output: true
nginx_config_debug_tasks: true
nginx_config_cleanup: true
nginx_config_cleanup_files:
- /etc/nginx/conf.d/default.conf
nginx_config_main_template_enable: true
nginx_config_main_template:
user: pi
http_enable: true
http_settings:
gzip:
enable: true
access_log_format:
- name: main
format: |-
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
access_log_location:
- name: main
location: /var/log/nginx/access.log
keepalive_timeout: 65
nginx_config_http_template_enable: true
nginx_config_http_template:
# - template_file: http/default.conf.j2
# conf_file_name: default.v1.conf
# conf_file_location: /etc/nginx/conf.d/
- servers:
- server_name: localhost
listen:
- ip: localhost
port: 80
gzip:
enable: true
root: "{{ ui_pkg_dst }}"
index: index.html
try_files: $uri $uri/index.html $uri.html =404
locations:
- location: /
root: "{{ ui_pkg_dst }}"
index: index.html
try_files: $uri $uri/index.html $uri.html =404
But it seems like the config file on the remote host is always empty or contains just the comment:
TASK [Gathering Facts] *******************************************************************************************************************************************************************************************
ok: [dum-e]
TASK [nginxinc.nginx : Check whether you are using a supported NGINX distribution] *******************************************************************************************************************************
ok: [dum-e] => {
"changed": false,
"msg": "Your OS, Debian is supported by NGINX Open Source"
}
TASK [nginxinc.nginx : Set up prerequisites] *********************************************************************************************************************************************************************
included: /Users/rolandgroza/.ansible/roles/nginxinc.nginx/tasks/prerequisites/prerequisites.yml for dum-e
TASK [nginxinc.nginx : Install dependencies] *********************************************************************************************************************************************************************
included: /Users/rolandgroza/.ansible/roles/nginxinc.nginx/tasks/prerequisites/install-dependencies.yml for dum-e
TASK [nginxinc.nginx : (Alpine Linux) Install dependencies] ******************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : (Debian/Ubuntu) Install dependencies] *****************************************************************************************************************************************************
ok: [dum-e]
TASK [nginxinc.nginx : (Amazon Linux/CentOS/Oracle Linux/RHEL) Install dependencies] *****************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : (SLES) Install dependencies] **************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : (FreeBSD) Install dependencies using package(s)] ******************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : (FreeBSD) Install dependencies using port(s)] *********************************************************************************************************************************************
skipping: [dum-e] => (item=security/ca_root_nss)
TASK [nginxinc.nginx : Check if SELinux is enabled] **************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Configure SELinux] ************************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Set up signing keys] **********************************************************************************************************************************************************************
included: /Users/rolandgroza/.ansible/roles/nginxinc.nginx/tasks/keys/setup-keys.yml for dum-e
TASK [nginxinc.nginx : (Alpine Linux) Set up NGINX signing key URL] **********************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : (Alpine Linux) Download NGINX signing key] ************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : (Debian/Red Hat/SLES OSs) Set up NGINX signing key URL] ***********************************************************************************************************************************
ok: [dum-e]
TASK [nginxinc.nginx : (Debian/Ubuntu) Add NGINX signing key] ****************************************************************************************************************************************************
ok: [dum-e]
TASK [nginxinc.nginx : (Amazon Linux/CentOS/Oracle Linux/RHEL/SLES) Add NGINX signing key] ***********************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Install NGINX Open Source] ****************************************************************************************************************************************************************
included: /Users/rolandgroza/.ansible/roles/nginxinc.nginx/tasks/opensource/install-oss.yml for dum-e
TASK [nginxinc.nginx : Install NGINX from repository] ************************************************************************************************************************************************************
included: /Users/rolandgroza/.ansible/roles/nginxinc.nginx/tasks/opensource/install-debian.yml for dum-e
TASK [nginxinc.nginx : (Debian/Ubuntu) Configure NGINX repository] ***********************************************************************************************************************************************
ok: [dum-e] => (item=deb [arch=amd64] https://nginx.org/packages/mainline/debian/ buster nginx)
ok: [dum-e] => (item=deb-src https://nginx.org/packages/mainline/debian/ buster nginx)
TASK [nginxinc.nginx : (Debian/Ubuntu) Install NGINX] ************************************************************************************************************************************************************
ok: [dum-e]
TASK [nginxinc.nginx : Install NGINX from source] ****************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Install NGINX from package] ***************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Install NGINX in Unix systems] ************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Set up NGINX Plus license] ****************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Install NGINX Plus] ***********************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Install NGINX modules] ********************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Remove NGINX Plus license] ****************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Modify systemd parameters] ****************************************************************************************************************************************************************
skipping: [dum-e]
[WARNING]: flush_handlers task does not support when conditional
TASK [nginxinc.nginx : Debug NGINX output] ***********************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Configure logrotate for NGINX] ************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx : Install NGINX Amplify] ********************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx_config : Set up SELinux] ********************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx_config : Cleanup NGINX config] **************************************************************************************************************************************************************
included: /Users/rolandgroza/.ansible/roles/nginxinc.nginx_config/tasks/config/cleanup-config.yml for dum-e
TASK [nginxinc.nginx_config : Find NGINX config files] ***********************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx_config : Remove NGINX config files] *********************************************************************************************************************************************************
changed: [dum-e] => (item=/etc/nginx/conf.d/default.conf)
TASK [nginxinc.nginx_config : Upload NGINX config] ***************************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx_config : Create NGINX config] ***************************************************************************************************************************************************************
included: /Users/rolandgroza/.ansible/roles/nginxinc.nginx_config/tasks/config/template-config.yml for dum-e
TASK [nginxinc.nginx_config : Ensure HTML directory exists] ******************************************************************************************************************************************************
skipping: [dum-e] => (item={'key': 'default', 'value': {'template_file': 'www/index.html.j2', 'html_file_name': 'index.html', 'html_file_location': '/usr/share/nginx/html', 'web_server_name': 'Default'}})
TASK [nginxinc.nginx_config : Dynamically generate HTML files] ***************************************************************************************************************************************************
skipping: [dum-e] => (item={'key': 'default', 'value': {'template_file': 'www/index.html.j2', 'html_file_name': 'index.html', 'html_file_location': '/usr/share/nginx/html', 'web_server_name': 'Default'}})
TASK [nginxinc.nginx_config : Configure NGINX modules] ***********************************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx_config : Ensure NGINX main directory exists] ************************************************************************************************************************************************
ok: [dum-e]
TASK [nginxinc.nginx_config : Dynamically generate NGINX main configuration file] ********************************************************************************************************************************
ok: [dum-e]
TASK [nginxinc.nginx_config : Ensure NGINX HTTP directory exists] ************************************************************************************************************************************************
ok: [dum-e] => (item={'key': 'servers', 'value': [{'server_name': 'localhost', 'listen': [{'ip': 'localhost', 'port': 80}], 'gzip': {'enable': True}, 'root': '/home/pi/ui', 'index': 'index.html', 'try_files': '$uri $uri/index.html $uri.html =404', 'locations': [{'location': '/', 'root': '/home/pi/ui', 'index': 'index.html', 'try_files': '$uri $uri/index.html $uri.html =404'}]}]})
TASK [nginxinc.nginx_config : Ensure NGINX proxy cache directories exist] ****************************************************************************************************************************************
TASK [nginxinc.nginx_config : Dynamically generate NGINX HTTP config files] **************************************************************************************************************************************
changed: [dum-e] => (item={'key': 'servers', 'value': [{'server_name': 'localhost', 'listen': [{'ip': 'localhost', 'port': 80}], 'gzip': {'enable': True}, 'root': '/home/pi/ui', 'index': 'index.html', 'try_files': '$uri $uri/index.html $uri.html =404', 'locations': [{'location': '/', 'root': '/home/pi/ui', 'index': 'index.html', 'try_files': '$uri $uri/index.html $uri.html =404'}]}]})
TASK [nginxinc.nginx_config : Dynamically generate NGINX stub status config file] ********************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx_config : Dynamically generate NGINX API config file] ****************************************************************************************************************************************
skipping: [dum-e]
TASK [nginxinc.nginx_config : Ensure NGINX stream directory exists] **********************************************************************************************************************************************
skipping: [dum-e] => (item={'key': 'default', 'value': {'template_file': 'stream/default.conf.j2', 'conf_file_name': 'default.conf', 'conf_file_location': '/etc/nginx/conf.d/stream/', 'network_streams': {'default': {'listen': {'listen_localhost': {'ip': '0.0.0.0', 'port': 80, 'ssl': False, 'opts': []}}, 'ssl': {'cert': '/etc/ssl/certs/default.crt', 'key': '/etc/ssl/private/default.key', 'dhparam': '/etc/ssl/private/dh_param.pem', 'protocols': 'TLSv1 TLSv1.1 TLSv1.2', 'ciphers': 'HIGH:!aNULL:!MD5', 'prefer_server_ciphers': True, 'session_cache': 'none', 'session_timeout': '5m', 'disable_session_tickets': False, 'trusted_cert': '/etc/ssl/certs/root_CA_cert_plus_intermediates.crt', 'ecdh_curve': 'auto'}, 'include_files': [], 'proxy_pass': 'backend', 'proxy_timeout': '3s', 'proxy_connect_timeout': '1s', 'proxy_protocol': False, 'proxy_ssl': {'cert': '/etc/ssl/certs/proxy_default.crt', 'key': '/etc/ssl/private/proxy_default.key', 'trusted_cert': '/etc/ssl/certs/proxy_ca.crt', 'protocols': 'TLSv1 TLSv1.1 TLSv1.2', 'ciphers': 'HIGH:!aNULL:!MD5', 'verify': False, 'verify_depth': 1, 'session_reuse': True}, 'health_check_plus': False}}, 'upstreams': {'upstream1': {'name': 'backend', 'lb_method': 'least_conn', 'zone_name': 'backend', 'zone_size': '64k', 'sticky_cookie': False, 'servers': {'server1': {'address': 'localhost', 'port': 8080, 'weight': 1, 'health_check': 'max_fails=1 fail_timeout=10s'}}}}}})
TASK [nginxinc.nginx_config : Dynamically generate NGINX stream config files] ************************************************************************************************************************************
skipping: [dum-e] => (item={'key': 'default', 'value': {'template_file': 'stream/default.conf.j2', 'conf_file_name': 'default.conf', 'conf_file_location': '/etc/nginx/conf.d/stream/', 'network_streams': {'default': {'listen': {'listen_localhost': {'ip': '0.0.0.0', 'port': 80, 'ssl': False, 'opts': []}}, 'ssl': {'cert': '/etc/ssl/certs/default.crt', 'key': '/etc/ssl/private/default.key', 'dhparam': '/etc/ssl/private/dh_param.pem', 'protocols': 'TLSv1 TLSv1.1 TLSv1.2', 'ciphers': 'HIGH:!aNULL:!MD5', 'prefer_server_ciphers': True, 'session_cache': 'none', 'session_timeout': '5m', 'disable_session_tickets': False, 'trusted_cert': '/etc/ssl/certs/root_CA_cert_plus_intermediates.crt', 'ecdh_curve': 'auto'}, 'include_files': [], 'proxy_pass': 'backend', 'proxy_timeout': '3s', 'proxy_connect_timeout': '1s', 'proxy_protocol': False, 'proxy_ssl': {'cert': '/etc/ssl/certs/proxy_default.crt', 'key': '/etc/ssl/private/proxy_default.key', 'trusted_cert': '/etc/ssl/certs/proxy_ca.crt', 'protocols': 'TLSv1 TLSv1.1 TLSv1.2', 'ciphers': 'HIGH:!aNULL:!MD5', 'verify': False, 'verify_depth': 1, 'session_reuse': True}, 'health_check_plus': False}}, 'upstreams': {'upstream1': {'name': 'backend', 'lb_method': 'least_conn', 'zone_name': 'backend', 'zone_size': '64k', 'sticky_cookie': False, 'servers': {'server1': {'address': 'localhost', 'port': 8080, 'weight': 1, 'health_check': 'max_fails=1 fail_timeout=10s'}}}}}})
RUNNING HANDLER [nginxinc.nginx_config : (Handler - NGINX Config) Check NGINX] ***********************************************************************************************************************************
ok: [dum-e]
RUNNING HANDLER [nginxinc.nginx_config : (Handler - NGINX Config) Print NGINX error if syntax check fails] *******************************************************************************************************
skipping: [dum-e]
RUNNING HANDLER [nginxinc.nginx_config : (Handler - NGINX Config) Start/reload NGINX] ****************************************************************************************************************************
changed: [dum-e]
TASK [nginxinc.nginx_config : Debug output] **********************************************************************************************************************************************************************
included: /Users/rolandgroza/.ansible/roles/nginxinc.nginx_config/tasks/config/debug-output.yml for dum-e
TASK [nginxinc.nginx_config : Register NGINX config] *************************************************************************************************************************************************************
ok: [dum-e]
TASK [nginxinc.nginx_config : Print NGINX config] ****************************************************************************************************************************************************************
ok: [dum-e] => {
"config_full.stdout_lines": [
"# configuration file /etc/nginx/nginx.conf:",
"#",
"# Ansible managed",
"#",
"",
"",
"user pi;",
"",
"",
"",
"events {",
"}",
"",
"http {",
" include /etc/nginx/mime.types;",
" default_type application/octet-stream;",
" log_format main '$remote_addr - $remote_user [$time_local] \"$request\" '",
"'$status $body_bytes_sent \"$http_referer\" '",
"'\"$http_user_agent\" \"$http_x_forwarded_for\"';",
" access_log /var/log/nginx/access.log main;",
" keepalive_timeout 65;",
" gzip on;",
"",
" include /etc/nginx/conf.d/*.conf;",
"}",
"",
"",
"# configuration file /etc/nginx/mime.types:",
"",
"types {",
" text/html html htm shtml;",
" text/css css;",
" text/xml xml;",
" image/gif gif;",
" image/jpeg jpeg jpg;",
" application/javascript js;",
" application/atom+xml atom;",
" application/rss+xml rss;",
"",
" text/mathml mml;",
" text/plain txt;",
" text/vnd.sun.j2me.app-descriptor jad;",
" text/vnd.wap.wml wml;",
" text/x-component htc;",
"",
" image/png png;",
" image/tiff tif tiff;",
" image/vnd.wap.wbmp wbmp;",
" image/x-icon ico;",
" image/x-jng jng;",
" image/x-ms-bmp bmp;",
" image/svg+xml svg svgz;",
" image/webp webp;",
"",
" application/font-woff woff;",
" application/java-archive jar war ear;",
" application/json json;",
" application/mac-binhex40 hqx;",
" application/msword doc;",
" application/pdf pdf;",
" application/postscript ps eps ai;",
" application/rtf rtf;",
" application/vnd.apple.mpegurl m3u8;",
" application/vnd.ms-excel xls;",
" application/vnd.ms-fontobject eot;",
" application/vnd.ms-powerpoint ppt;",
" application/vnd.wap.wmlc wmlc;",
" application/vnd.google-earth.kml+xml kml;",
" application/vnd.google-earth.kmz kmz;",
" application/x-7z-compressed 7z;",
" application/x-cocoa cco;",
" application/x-java-archive-diff jardiff;",
" application/x-java-jnlp-file jnlp;",
" application/x-makeself run;",
" application/x-perl pl pm;",
" application/x-pilot prc pdb;",
" application/x-rar-compressed rar;",
" application/x-redhat-package-manager rpm;",
" application/x-sea sea;",
" application/x-shockwave-flash swf;",
" application/x-stuffit sit;",
" application/x-tcl tcl tk;",
" application/x-x509-ca-cert der pem crt;",
" application/x-xpinstall xpi;",
" application/xhtml+xml xhtml;",
" application/xspf+xml xspf;",
" application/zip zip;",
"",
" application/octet-stream bin exe dll;",
" application/octet-stream deb;",
" application/octet-stream dmg;",
" application/octet-stream iso img;",
" application/octet-stream msi msp msm;",
"",
" application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;",
" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;",
" application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;",
"",
" audio/midi mid midi kar;",
" audio/mpeg mp3;",
" audio/ogg ogg;",
" audio/x-m4a m4a;",
" audio/x-realaudio ra;",
"",
" video/3gpp 3gpp 3gp;",
" video/mp2t ts;",
" video/mp4 mp4;",
" video/mpeg mpeg mpg;",
" video/quicktime mov;",
" video/webm webm;",
" video/x-flv flv;",
" video/x-m4v m4v;",
" video/x-mng mng;",
" video/x-ms-asf asx asf;",
" video/x-ms-wmv wmv;",
" video/x-msvideo avi;",
"}",
"",
"# configuration file /etc/nginx/conf.d/default.conf:",
"#",
"# Ansible managed",
"#"
]
}
Steps to reproduce the behavior:
/etc/nginx/conf.d/default.conf
contentsI'd expect the config file on the remote host to be generated with the config I've setup.
---
roles:
# https://github.com/nginxinc/ansible-role-nginx
- src: nginxinc.nginx
version: 0.19.1
# https://github.com/nginxinc/ansible-role-nginx-config
- src: nginxinc.nginx_config
version: 0.3.3
❯ ansible --version
ansible 2.10.2
config file = /Users/rolandgroza/Work/jigs/ansible.cfg
configured module search path = ['/Users/rolandgroza/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/rolandgroza/.pyenv/versions/3.8.6/envs/python-3.8/lib/python3.8/site-packages/ansible
executable location = /Users/rolandgroza/.pyenv/versions/python-3.8/bin/ansible
python version = 3.8.6 (default, Nov 1 2020, 20:18:23) [Clang 11.0.3 (clang-1103.0.32.62)]
Add any other context about the problem here.
I think the issue is that you are using the configuration syntax that 0.4.0
is going to use when it's released vs the configuration syntax that 0.3.3
uses. Might I suggest pulling the latest commit from main and checking if that works?
I seem to be seeing the same issue as reported here.
I think the issue is that you are using the configuration syntax that
0.4.0
is going to use when it's released vs the configuration syntax that0.3.3
uses. Might I suggest pulling the latest commit from main and checking if that works?
Yeah, that seems to be issue. I've pulled the last commit and tested it and the config is generated as expected.
Indeed, seems that pulling the latest from makes it work. Will this fix make it to the ansible-galaxy repository?
It will make it to ansible-galaxy when 0.4.0
is released. That being said, I am holding on releasing 0.4.0
until I finish refactoring the various templates to a more sustainable development model (using macros).
I'll leave this issue open until 0.4.0
is released in case anyone else encounters a similar issue.
@alessfg I just burned a couple of hours chasing down why my seemingly valid sytax wasn't working with 0.3.3
. Is there an ETA on 0.4.0
?
Sadly, no. Other higher priority tasks have kept me from dedicating as much time as I'd like to the Ansible roles. That being said, what I can do is add a disclaimer to the README for the time being pointing people to the 0.3.3
docs if they are using the latest release (instead of pulling from GitHub).
Aaand done https://github.com/nginxinc/ansible-role-nginx-config/commit/030e2827a04a2b25bf319724ac680998d39c0fb5 -- I'm also going to change this issue's title and pin it to try to avoid people loosing unnecessary time figuring out why the latest examples are not working.
Most helpful comment
Sadly, no. Other higher priority tasks have kept me from dedicating as much time as I'd like to the Ansible roles. That being said, what I can do is add a disclaimer to the README for the time being pointing people to the
0.3.3
docs if they are using the latest release (instead of pulling from GitHub).