From e00313bb3613d0db74c5a10150345a7380bd46b0 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sat, 5 Mar 2016 15:07:39 +0100 Subject: [PATCH] [WIP] FreeBSD install ok --- Vagrantfile | 17 +++++++++++ defaults/main.yml | 8 ++--- tasks/config.yml | 4 +-- tasks/{install.yml => install_Debian.yml} | 0 tasks/install_FreeBSD.yml | 15 ++++++++++ tasks/main.yml | 6 +++- tasks/upstream.yml | 8 +++-- tasks/vhost.yml | 20 ++++++------- templates/etc/nginx/nginx.conf.j2 | 2 +- tests/test.yml | 36 ++++++++++++++--------- vars/Debian.yml | 3 ++ vars/FreeBSD.yml | 5 ++++ 12 files changed, 89 insertions(+), 35 deletions(-) rename tasks/{install.yml => install_Debian.yml} (100%) create mode 100644 tasks/install_FreeBSD.yml create mode 100644 vars/Debian.yml create mode 100644 vars/FreeBSD.yml diff --git a/Vagrantfile b/Vagrantfile index 6051f70..b52c54a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,6 +6,7 @@ Vagrant.configure("2") do |config| vms = [ + [ "freebsd-10.2", "freebsd/FreeBSD-10.2-STABLE" ], [ "debian-wheezy", "debian/wheezy64" ], [ "debian-jessie", "debian/jessie64" ], [ "debian-stretch", "sharlak/debian_stretch_64" ] @@ -21,11 +22,27 @@ Vagrant.configure("2") do |config| m.vm.box = vm[1] m.vm.network "private_network", type: "dhcp" + # See: https://forums.freebsd.org/threads/52717/ + if vm[0] = "freebsd-10.2" + m.vm.guest = :freebsd + m.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true + m.ssh.shell = "sh" + #m.vm.base_mac = "0800278DFFF5" + m.vm.base_mac = "080027D14C66" + #m.vm.network "public_network", bridge: 'enp4s0', auto_config: false + m.vm.provision "shell", inline: "pkg install -y python bash" + end + m.vm.provision "ansible" do |ansible| ansible.playbook = "tests/test.yml" ansible.groups = { "test" => [ vm[0] ] } ansible.verbose = 'vv' ansible.sudo = true + if vm[0] = "freebsd-10.2" + ansible.extra_vars = { + ansible_python_interpreter: '/usr/local/bin/python' + } + end end end end diff --git a/defaults/main.yml b/defaults/main.yml index 68a5320..86c8b19 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -8,7 +8,6 @@ nginx_backports: false # nginx_root: "/srv/www" nginx_log_dir: '/var/log/nginx' -nginx_pid: '/run/nginx.pid' nginx_resolver_hosts: ['8.8.8.8', '8.8.4.4'] nginx_resolver_valid: '300s' nginx_resolver_timeout: '5s' @@ -20,9 +19,9 @@ nginx_default_vhost_ssl: null # # Nginx directories # -nginx_htpasswd_dir: '/etc/nginx/htpasswd' -nginx_ssl_dir: '/etc/nginx/ssl' -nginx_helper_dir: '/etc/nginx/helper' +nginx_htpasswd_dir: '{{ nginx_etc_dir}}/htpasswd' +nginx_ssl_dir: '{{ nginx_etc_dir}}/ssl' +nginx_helper_dir: '{{ nginx_etc_dir}}/helper' # # Load upstream @@ -45,7 +44,6 @@ nginx_worker_processes: '{{ ansible_processor_vcpus }}' # nginx_events_worker_connections: '512' nginx_events_multi_accept: 'on' -nginx_events_use: 'epoll' # # Nginx HTTP diff --git a/tasks/config.yml b/tasks/config.yml index 838ac0f..7aea924 100644 --- a/tasks/config.yml +++ b/tasks/config.yml @@ -3,7 +3,7 @@ - name: TEMPLATE | Deploy nginx.conf template: > src=etc/nginx/nginx.conf.j2 - dest=/etc/nginx/nginx.conf + dest="{{ nginx_etc_dir }}/nginx.conf" notify: reload nginx - name: TEMPLATE | Deploy all helpers @@ -16,6 +16,6 @@ - name: TEMPLATE | Deploy custom http configuration template: > src=etc/nginx/conf.d/custom.conf.j2 - dest=/etc/nginx/conf.d/custom.conf + dest="{{ nginx_etc_dir }}/conf.d/custom.conf" notify: reload nginx diff --git a/tasks/install.yml b/tasks/install_Debian.yml similarity index 100% rename from tasks/install.yml rename to tasks/install_Debian.yml diff --git a/tasks/install_FreeBSD.yml b/tasks/install_FreeBSD.yml new file mode 100644 index 0000000..2083c5e --- /dev/null +++ b/tasks/install_FreeBSD.yml @@ -0,0 +1,15 @@ +--- + +- name: PKGNG | Install nginx and related tools + pkgng: name=nginx state=present + with_items: + - nginx + - py27-passlib + - curl + +- name: FILE | Create configuration dir (like Debian) + file: path="{{ nginx_etc_dir }}/{{ item }}" state=directory + with_items: + - conf.d + - sites-available + - sites-enabled diff --git a/tasks/main.yml b/tasks/main.yml index 9a9e96c..7768d31 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,7 +1,11 @@ --- + +- name: INCLUDE_VARS | Related to OS + include_vars: "{{ ansible_distribution }}.yml" + - name: INCLUDE | Install - include: install.yml + include: install_{{ ansible_distribution }}.yml - name: INCLUDE | Prepare include: prepare.yml diff --git a/tasks/upstream.yml b/tasks/upstream.yml index cda9765..4092630 100644 --- a/tasks/upstream.yml +++ b/tasks/upstream.yml @@ -1,11 +1,15 @@ --- - name: TEMPLATE | Deploy PHP upstream to Nginx - template: src=etc/nginx/upstream/php.conf.j2 dest=/etc/nginx/conf.d/php.conf + template: > + src=etc/nginx/upstream/php.conf.j2 + dest="{{ nginx_etc_dir }}/conf.d/php.conf" when: nginx_php notify: reload nginx - name: TEMPLATE | Deploy other upstreams - template: src=etc/nginx/upstream/upstream.conf.j2 dest=/etc/nginx/conf.d/upstream-{{ item.name }}.conf + template: > + src=etc/nginx/upstream/upstream.conf.j2 + dest={{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf with_items: "{{ nginx_upstreams }}" notify: reload nginx diff --git a/tasks/vhost.yml b/tasks/vhost.yml index e20d82b..ba29240 100644 --- a/tasks/vhost.yml +++ b/tasks/vhost.yml @@ -17,8 +17,8 @@ file: > path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public state=directory - owner={{ item.owner | default('www-data') }} - group={{ item.group | default('www-data') }} + owner={{ item.owner | default(nginx_user) }} + group={{ item.group | default(nginx_user) }} mode={{ item.mode | default('0755') }} with_items: "{{ nginx_vhosts }}" when: > @@ -30,21 +30,21 @@ - name: TEMPLATE | Create vhosts template: > src=etc/nginx/sites-available/{{ item.template if item.redirect_to is not defined else '_redirect' }}.j2 - dest=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} + dest={{ nginx_etc_dir }}/sites-available/{{ item.name if item.name is string else item.name[0] }} with_items: "{{ nginx_vhosts }}" notify: reload nginx when: item.delete is not defined or not item.delete - name: FILE | Delete vhosts - file: path=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent + file: path={{ nginx_etc_dir }}/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent with_items: "{{ nginx_vhosts }}" notify: reload nginx when: item.delete is defined and item.delete - name: FILE | Enable vhosts file: > - src=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} - dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} + src={{ nginx_etc_dir }}/sites-available/{{ item.name if item.name is string else item.name[0] }} + dest={{ nginx_etc_dir }}/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=link with_items: "{{ nginx_vhosts }}" notify: reload nginx @@ -54,22 +54,22 @@ (item.delete is not defined or not item.delete) - name: FILE | Disable vhosts - file: path=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent + file: path={{ nginx_etc_dir}}/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent with_items: "{{ nginx_vhosts }}" notify: reload nginx when: (item.enable is defined and not item.enable) or (item.delete is defined and item.delete) - name: FILE | Delete default vhost when explicitely defined file: > - path=/etc/nginx/sites-enabled/default + path={{ nginx_etc_dir }}/sites-enabled/default state=absent notify: reload nginx when: nginx_default_vhost is not none - name: FILE | Auto set default vhost file: > - src=/etc/nginx/sites-available/default - dest=/etc/nginx/sites-enabled/default + src={{ nginx_etc_dir }}/sites-available/default + dest={{ nginx_etc_dir }}/sites-enabled/default state=link notify: reload nginx when: nginx_default_vhost is none diff --git a/templates/etc/nginx/nginx.conf.j2 b/templates/etc/nginx/nginx.conf.j2 index 06a97a8..060915d 100644 --- a/templates/etc/nginx/nginx.conf.j2 +++ b/templates/etc/nginx/nginx.conf.j2 @@ -14,7 +14,7 @@ events { http { types_hash_max_size {{ nginx_http_types_hash_max_size }}; - include /etc/nginx/mime.types; + include {{ nginx_etc_dir }}/mime.types; default_type {{ nginx_http_default_type }}; access_log {{ nginx_http_access_log }}; diff --git a/tests/test.yml b/tests/test.yml index 2939ec4..87e23b3 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -2,20 +2,27 @@ - hosts: all pre_tasks: - - name: APT_REPOSITORY | Install backports - apt_repository: repo='deb http://httpredir.debian.org/debian {{ ansible_distribution_release }}-backports main' state=present - - name: APT | Install needed packages - apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present - with_items: - - php5-fpm - - curl - - fcgiwrap - - name: SERVICE | Force start services - service: name={{ item }} state=started - register: sf - with_items: - - php5-fpm - - fcgiwrap + - block: + - name: APT_REPOSITORY | Install backports + apt_repository: repo='deb http://httpredir.debian.org/debian {{ ansible_distribution_release }}-backports main' state=present + - name: APT | Install needed packages + apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present + with_items: + - php5-fpm + - curl + - fcgiwrap + - name: SERVICE | Force start services + service: name={{ item }} state=started + register: sf + with_items: + - php5-fpm + - fcgiwrap + when: ansible_distribution == 'Debian' + - block: + - name: SET_FACT | FreeBSD web user + set_fact: + nginx_user: 'www' + when: ansible_distribution == 'FreeBSD' - name: PAUSE | Prevent bugs (CGI not fully loaded) pause: seconds=5 when: sf.changed @@ -29,6 +36,7 @@ # Internal vars int_ansible_ssl_dir: '/etc/ansible-ssl' # Role vars + nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number nginx_backports: true nginx_php: true nginx_upstreams: diff --git a/vars/Debian.yml b/vars/Debian.yml new file mode 100644 index 0000000..4f7c86f --- /dev/null +++ b/vars/Debian.yml @@ -0,0 +1,3 @@ +nginx_events_use: 'epoll' +nginx_pid: '/run/nginx.pid' +nginx_etc_dir: '/etc/nginx' diff --git a/vars/FreeBSD.yml b/vars/FreeBSD.yml new file mode 100644 index 0000000..96da262 --- /dev/null +++ b/vars/FreeBSD.yml @@ -0,0 +1,5 @@ +nginx_events_use: 'kqueue' +nginx_pid: '/var/run/nginx.pid' +nginx_etc_dir: '/usr/local/etc/nginx' + +# TODO: it's a dirty to force variable here!