Bergold
Enthusiast
Enthusiast

Invoke-VMScript

Jump to solution

Hi,

we use ubuntu 12. / 14. lts for some Services. For the first runtime i want to use invoke-vmscript to configure the basics of the operations systems - such as nic configuration. If i call invoke-vmscript with guest credentials the i get the error: "Operation not permitted". The error is known because i call it as normal user and not as sudo.

The ScriptText is easy: ifconfig eth0 10.0.0.1 netmask 255.255.255.0 up

How is it possible that i call this ScriptText as sudo via PowerCli?

0 Kudos
1 Solution

Accepted Solutions
sajal1
VMware Employee
VMware Employee

Hi,

You can do that in the following way:

Invoke-VMScript -VM <VMname> -ScriptText "sudo -u root ifconfig eth0 10.0.0.1 netmask 255.255.255.0 up" -GuestUser <User Id> -GuestPassword <Password>

But remember the following point. From VMScript you will not be able to successfully run it , if this asks for the password. In that case you will get the following error:

sudo: no tty present and no askpass program specified

Cause there will be no tty available for password ask from inside the Linux OS. So you need to add the user to the Sudoers file with NOPASSWD option so that it will not ask for any password. For example, if the user is user1 then I will add the following line in the sudoers file.

username ALL = NOPASSWD: /fullpath/to/command, /fullpath/to/othercommand

eg

user1 ALL = NOPASSWD: /sbin/poweroff, /sbin/start, /sbin/stop

Or if you want to give permission to all the commands then:

user1 ALL =(ALL) NOPASSWD: ALL

So if this is already added in the sudoers file then the command will work.

Please let me know if you find any issues

View solution in original post

0 Kudos
1 Reply
sajal1
VMware Employee
VMware Employee

Hi,

You can do that in the following way:

Invoke-VMScript -VM <VMname> -ScriptText "sudo -u root ifconfig eth0 10.0.0.1 netmask 255.255.255.0 up" -GuestUser <User Id> -GuestPassword <Password>

But remember the following point. From VMScript you will not be able to successfully run it , if this asks for the password. In that case you will get the following error:

sudo: no tty present and no askpass program specified

Cause there will be no tty available for password ask from inside the Linux OS. So you need to add the user to the Sudoers file with NOPASSWD option so that it will not ask for any password. For example, if the user is user1 then I will add the following line in the sudoers file.

username ALL = NOPASSWD: /fullpath/to/command, /fullpath/to/othercommand

eg

user1 ALL = NOPASSWD: /sbin/poweroff, /sbin/start, /sbin/stop

Or if you want to give permission to all the commands then:

user1 ALL =(ALL) NOPASSWD: ALL

So if this is already added in the sudoers file then the command will work.

Please let me know if you find any issues

0 Kudos