Update sudoers file in multiple servers with a bash script

I have 50 Linux servers and can login to the servers without root password (I know the password). Now I would like to add 3 lines in sudoers file on each servers. Obviously logging into 50 servers and adding lines are painful. Is there a different approach we can achieve this by a bash script or a loop?


Rather than editing /etc/sudoers directly:

Most Linux distributions support by default a modular sudo configuration by loading files / configuration snippets from drop-in directory via the #includedir directive.

Note the # in that is NOT A COMMENT marker.

## Read drop-in files from /etc/sudoers.d (the # here does not mean a comment)
#includedir /etc/sudoers.d

That allows you to copy/upload the sudo directives you want to set as separate drop-in file, e.g. /etc/sudoers.d/ansible-user which is much easier to script and maintain than a single configuration file.