Question

On the Chef workstation, I use the command -

    knife ssh 'name:myserver.org.com' -x myUserName -P myClearTextPassword  "sudo chef-client"

This works fine, prompts for my sudo password and executes the cookbook on the destination chef node. So far so good.

Now, I am trying to do this, as part of a build operation in a Jenkins job in an ANT script which runs on a Windows System. The ANT script is as follows -

    <project name="MyProject" default="init" basedir=".">
<target name="init">
    <property name="mypassword" value="myClearTextPassword" />
    <echo message="Executing the knife script"/>
    <exec executable="cmd" failonerror="true" inputstring="${mypassword}">
        <arg line="/c knife ssh name:myserver.org.com -x myUserName -P myClearTextPassword sudo chef-client" />
    </exec>
</target>

The ANT script, when executed waits on the SUDO password -

    C:\chef-repo>ant
    Buildfile: C:\chef-repo\build.xml
    init:
    [echo] Executing the knife script
    [exec] cwllx0001.hq.target.com knife sudo password:

My aim is to execute this ANT script such that it DOES NOT wait for the sudo password. Any way we can achieve this?

Was it helpful?

Solution 2

Try this.

--use-sudo-password
Indicates that a bootstrap operation is done using sudo, with the password specified by the -P (or --ssh-password) option.

a better way would be

-i IDENTITY_FILE, --identity-file IDENTITY_FILE

The SSH identity file used for authentication. Key-based authentication is recommended.

http://docs.opscode.com/knife_bootstrap.html

OTHER TIPS

You need to add an entry for the user in /etc/sudoers file to not prompt for password

You need to add an entry similar to the one below in /etc/sudoers

<username> ALL=(ALL) NOPASSWD: ALL

you can add this line to /etc/sudoers using chef bash resource or execute resource

You'll need to add the current user to the sudoers group and give it password-less sudo access on that command:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top