diff --git a/tasks/sudoers.yml b/tasks/sudoers.yml index b249a00..4a39c20 100644 --- a/tasks/sudoers.yml +++ b/tasks/sudoers.yml @@ -1,10 +1,21 @@ --- +# If the user installs GNU sed through homebrew the path is different. +- name: Register path to sed. + command: which sed + register: sed_which_result + changed_when: false + when: sed_path is undefined + +- name: Define sed_path variable. + set_fact: + sed_path: "{{ sed_which_result.stdout }}" + when: sed_path is undefined + # Sudoers configuration (enables more convenient Vagrant usage). - name: Copy sudoers configuration into place. - copy: - src: files/etc/sudoers + template: + src: templates/sudoers.j2 dest: /etc/sudoers mode: 0440 validate: 'visudo -cf %s' become: yes - when: configure_sudoers diff --git a/files/etc/sudoers b/templates/sudoers.j2 similarity index 91% rename from files/etc/sudoers rename to templates/sudoers.j2 index f66e16c..ea4be0c 100644 --- a/files/etc/sudoers +++ b/templates/sudoers.j2 @@ -47,7 +47,7 @@ root ALL=(ALL) ALL # Vagrant sudoers config Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart -Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports +Cmnd_Alias VAGRANT_EXPORTS_REMOVE = {{ sed_path }} -E -e /*/ d -ibak /etc/exports Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts -Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/bin/sed -i -e /*/ d /etc/hosts +Cmnd_Alias VAGRANT_HOSTS_REMOVE = {{ sed_path }} -i -e /*/ d /etc/hosts %admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE, VAGRANT_HOSTS_ADD, VAGRANT_HOSTS_REMOVE