diff --git a/templates/jperm/role_sudo.j2 b/templates/jperm/role_sudo.j2 index 4fe2e82da..27ce08ea6 100644 --- a/templates/jperm/role_sudo.j2 +++ b/templates/jperm/role_sudo.j2 @@ -4,6 +4,13 @@ real_file=/etc/sudoers tmp_file=$(mktemp /tmp/XXXXXXX) +# fixed sudoers file path in bsd +isbsd=$(uname -a | grep -i 'freebsd' &> /dev/null && echo "yes" || echo "no") +if [ $isbsd == "yes" ]; then + real_file=/usr/local/etc/sudoers +fi + + # Backup sudoers file cp ${real_file} ${tmp_file} @@ -13,7 +20,6 @@ add_cmd_alias() { {% for sudo_name, sudo_cmd in sudo_alias.items %} {% if sudo_name != 'ALL' %} if $(grep '^Cmnd_Alias \<{{ sudo_name }}\>' ${sudo_file} &> /dev/null); then - isbsd=$(uname -a | grep -i 'freebsd' &> /dev/null && echo "yes" || echo "no") if [ $isbsd == "yes" ]; then sed -i .bk 's@^Cmnd_Alias \<{{ sudo_name }}\>.*@Cmnd_Alias {{ sudo_name }} = {{ sudo_cmd }}@g' ${sudo_file} else @@ -32,7 +38,6 @@ add_role_chosen() { sudo_file=$1 {% for user, alias in sudo_user.items %} if $(grep '^{{ user }}\>' ${sudo_file} &> /dev/null); then - isbsd=$(uname -a | grep -i 'freebsd' &> /dev/null && echo "yes" || echo "no") if [ $isbsd == "yes" ]; then sed -i .bk 's@^{{ user }}\>.*@{{ user }} ALL = (root) NOPASSWD: {{ alias }}@g' ${sudo_file} else