From 3746e798b67ee6e874b3d674e3ad79277fcf66e6 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Mon, 25 May 2015 00:15:49 +0300 Subject: [PATCH] roles/nginx: Use template for nginx repo A template is better than ansible's `apt_repository` module because we can idempotently control the contents of the file based on vari- ables. Signed-off-by: Alan Orth --- roles/nginx/defaults/main.yml | 4 ++++ roles/nginx/tasks/main.yml | 8 ++------ roles/nginx/templates/nginx_org_packages_ubuntu.list.j2 | 5 +++++ 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 roles/nginx/templates/nginx_org_packages_ubuntu.list.j2 diff --git a/roles/nginx/defaults/main.yml b/roles/nginx/defaults/main.yml index 1104f14..df3863f 100644 --- a/roles/nginx/defaults/main.yml +++ b/roles/nginx/defaults/main.yml @@ -13,4 +13,8 @@ nginx_tls_protocols: TLSv1 TLSv1.1 TLSv1.2 # TLS key directory tls_key_dir: /etc/ssl/private +# stable is 1.8.x +# mainline is 1.9.x +nginx_version: mainline + # vim: set ts=2 sw=2: diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml index 44d416b..6332085 100644 --- a/roles/nginx/tasks/main.yml +++ b/roles/nginx/tasks/main.yml @@ -3,12 +3,8 @@ apt_key: url=http://nginx.org/keys/nginx_signing.key state=present tags: nginx -- name: Add nginx.org mainline repo - apt_repository: repo="deb http://nginx.org/packages/mainline/ubuntu/ {{ ansible_distribution_release }} nginx" state=absent - tags: nginx - -- name: Add nginx.org stable repo - apt_repository: repo="deb http://nginx.org/packages/ubuntu/ {{ ansible_distribution_release }} nginx" state=present +- name: Add nginx.org repo + template: src=nginx_org_packages_ubuntu.list.j2 dest=/etc/apt/sources.list.d/nginx_org_packages_ubuntu.list owner=root group=root mode=0644 tags: nginx - name: Install nginx diff --git a/roles/nginx/templates/nginx_org_packages_ubuntu.list.j2 b/roles/nginx/templates/nginx_org_packages_ubuntu.list.j2 new file mode 100644 index 0000000..76b3159 --- /dev/null +++ b/roles/nginx/templates/nginx_org_packages_ubuntu.list.j2 @@ -0,0 +1,5 @@ +{% if nginx_version == "stable" %} +deb http://nginx.org/packages/ubuntu/ {{ ansible_distribution_release }} nginx +{% elif nginx_version == "mainline" %} +deb http://nginx.org/packages/mainline/ubuntu/ {{ ansible_distribution_release }} nginx +{% endif %}