Append 2 lines in visudo /etc/sudoers

64 views
Skip to first unread message

Hamim Ismail

unread,
Feb 27, 2023, 2:29:58 PM2/27/23
to Ansible Project
Append 2 lines in /etc/sudoers

Hi I have 2 lines starting with User_Alias

How do i make sure both lines get appended

at the moment only the last line is being appended using this playbook



tasks:

- name: add someuser to end of line

lineinfile:

dest: /etc/sudoers

state: present

regexp: '^(User_Alias(.*)$)'

backrefs: yes

backup: yes

line: '\1, someuser'


Output:


User_Alias SAP_ADMIN =user1, user2, user3, (see its blank here)

User_Alias ORA_ADMIN = user1, user2 ,user3, someuser

Nico Kadel-Garcia

unread,
Feb 27, 2023, 6:32:38 PM2/27/23
to ansible...@googlegroups.com
On Mon, Feb 27, 2023 at 2:30 PM Hamim Ismail <hami...@gmail.com> wrote:
Append 2 lines in /etc/sudoers

Hi I have 2 lines starting with User_Alias

How do i make sure both lines get appended

at the moment only the last line is being appended using this playbook


You don't. You put that content in as a separate, template based file in /etc/sudoers.d/whateveryoulike.conf, with ownership set to root and permissions set to 440.

tasks:

- name: add someuser to end of line

lineinfile:

dest: /etc/sudoers

state: present

regexp: '^(User_Alias(.*)$)'

backrefs: yes

backup: yes

line: '\1, someuser'


Output:


User_Alias SAP_ADMIN =user1, user2, user3, (see its blank here)

User_Alias ORA_ADMIN = user1, user2 ,user3, someuser

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9fa81932-2293-442d-996e-575f476aca08n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages