how to run chef-client remotely with dynamic attributes - ruby

I am trying to run chef-client remotely using knife run, however I would like to supply set of attributes at run time.
knife winrm -m 10.10.10.10 -x myuser -P mypassword chef-client
Ideal command:
knife winrm -m 10.10.10.10 -x myuser -P mypassword chef-client -j c:\.chef\dna.json

Node attribute data lives on the Chef Server, so you set it there (knife node edit, etc) rather than when you run chef-client. In general you can't easily change per-node data after initial creation, at least not without a bunch of caveats.

Related

SSH sudo inside script different behaviour

I'm trying to set some automation inside local network and started working with some shell scripting and something that I saw - very strange behaviour SSH inside script according to how script running(with or without sudo):
What I have:
ComputerA and ComputerB.
Inside ComputerA:
A shell script script.sh:
cp /dir1/file1 /dir2/file2
ssh username#ComputerB "sudo reboot"
/etc/ssh/ssh_config file with some configurations to work without ssh-keys (they always changes on ComputerB):
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
GlobalKnownHostsFile=/dev/null
Inside ComputerB:
In /etc/sudoers file:
username ALL=(ALL:ALL) NOPASSWD:ALL
When I connecting through SSH to ComputerA and running script.sh without sudo, I get permission error to write to /dir2 (it's OK) and next command on ComputerB executes normally (reboots ComputerB), but I'm running sudo script.sh. It copy file and then I got strange - SSH asks me username password. Tried different variants to change ssh command to something like:
ssh -t username#ComputerB "echo user_pass | sudo -S reboot"
but nothing helped.
So I need help to figure out what happens and what to do to execute sudo script.sh without entering password for ssh command inside.
Thanks!
Don't run script.sh with sudo on computerA; instead modify the script like so:
sudo cp /dir1/file1 /dir2/file2
ssh username#ComputerB "sudo reboot"
The reason that you're seeing the strange behaviour is that you're actually becoming root on computerA (I assume you have a keypair set-up for your regular user and expect to connect to computerB passwordless?), and that root on computerA doesn't have a keypair that computerB knows about.

Remote SSH without reentering Password

I am trying to loop through a list of remote servers, ssh to them and get hardware info, but this requires sudo password, and I don't want to have to type in password for each loop, and unsure how to accomplish that. My script below:
#!/bin/bash
for i in $(cat server-list.txt); do
ssh -t username#${i} 'sudo -s <dmidecode -t 1>';
done
Note: all system commands require sudo password.

Hadoop - requestion for network lan password during starting cluster

I can't understant what password is expected by hadoop.
I configured it according to tutorial. I do:
sudo su
#bash start-dfs.sh
And now it expects someting like password lan's network. I have no idea what should I write.
As you can see, I run script as root. Of course master (from that I run script) may ssh to slaves as root without password (I configured and tested it).
Disclaimer: It is possbile that I give incorrect name (for example for script name - it is beacause of I don't understand exactly now. However I am sure that it was about something like lan's network password)
Help me please, for which a password is it?
Edit: I was using http://backtobazics.com/big-data/setup-multi-node-hadoop-2-6-0-cluster-with-yarn/
It seems you may not setup passwordless-ssh. Passwordless-ssh is required to run hadoop services (daemons). So try to setup ssh among nodes
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
$ chmod 0600 ~/.ssh/authorized_keys
Then ssh user#hostname

How to set up a Chef Node on an ec2 instance?

I am trying to use knife bootstrap command from mac terminal
"knife bootstrap node_domain_or_IP -x username -P password -N name_for_node --sudo"
But the problem is, I don't have user name and password, instead the ec2-user has this private key stored in my local work station which helps me to connect to the server.
I find lot of examples for debian os, but hard to find for RHEL on ec2.
OS: RHEL 6
Chef: 11.1.6
Kindly let me know if any details you need to help me better.
Even with host keys you will have a username. Typically, if you are using
ssh -i somekey user#host_or_ip
to ssh to your node, then you would use
knife bootstrap node_domain_or_IP -x username -i sameKey -N chef_name_you_want --sudo
Notice, I use -i rather than -P. That's all there is to it.
An even better option for most people is to use knife ec2 server create to create your node in the first place. This will create the node in AWS and bootstrap it, all in one command.

bash - running remote script from local machine

I tried this:
#!bin/bash
ssh user#host.com 'sudo /etc/init.d/script restart'
But I get this error:
sudo: no tty present and no askpass program specified
How can I run that script? Now when I need to run that script I do these steps:
ssh user#host.com
sudo /etc/init.d/script restart
But I don't want to manually log in to remote server all the time and then enter restart command.
Can I write local script that I could run so I would only need to enter password and it would run remote script and restart the process?
You can use -t option in ssh command to attach a pseudo-tty with your ssh command:
ssh -t -t user#host.com 'sudo /etc/init.d/script restart'
As per man ssh:
-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

Resources