[SOLVED] Connecting to Puppet Server with Shell Scripting
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello, I am trying to write a shell script that will automatically install puppet agent and then connect to the puppet host. I was able to successfully get the script to install puppet. However, I am currently stuck because I don't know how to write part of the script to edit the puppet.conf file.
I wrote the line
Quote:
sudo vi +15 /etc/puppet/puppet.conf
to go to the specific line that I need to edit in the puppet configuration file. From there, I need to add the line "server = 'server_hostname'" so that the server's hostname is added to the file. But I don't know how to 1. Get the server's hostname from the script and 2. Add the line in the script that writes "server = server_hostname".
Thank you for your response. I believe you were correct with the command sed. But I don't think the one you posted was formatted correctly. When I put it into my script and ran it, I got an error:
Try more like sed -i '15iserver=server_hostname' FILE
This worked on my file as long as there is there at least >= as the line at which you are trying to insert.
sed doesn't seem to like my spaces. I'm not super familiar with the command, only light use. Note that this will print literally
server=server_hostname
on line 15. I'm not exactly sure how you would pull that variable in though. I think that is probably a job for echo but again I'm not super familiar with it yet either haha
Last edited by TheEzekielProject; 12-15-2016 at 09:39 PM.
Thank you for your response. I believe you were correct with the command sed. But I don't think the one you posted was formatted correctly. When I put it into my script and ran it, I got an error:
It's formatted correctly. But your copy/paste is adding messed up control characters between windows/mac and the linux terminal.
Problem with using 'line 15' as basis for the insertion, is that it is arbitrary. There is a high chance that if the user adds/deletes lines then you would end up inserting it in places you don't want to. Instead, you can use some familiar lines like certname or environment to base it from. For example:
Code:
sed -i '/^\s*certname/a \\tserver = server_hostname' puppet.conf
if the user adds/deletes lines then you would end up inserting it in places you don't want to
Well that isn't really an issue because this script is set to run automatically when a user starts up their machine so they wouldn't have installed puppet or opened up the configuration file yet. I simply changed it using
Quote:
echo " server = hostname">> etc/puppet/puppet.conf
and that ended up working. Thank you everyone for responding
Was it because you typed it in instead of copy/pasted?
If so, there are usually changes you can make to your emulator/shell/editor that will cause it to refuckulate correctly and stop causing \r and ^M pasting errors. If that is something you want to figure out, start a new thread and let us know your OS, text editor and shell, and we could help out.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.