Search code examples
execchef-infrasudoknife

Chef : Password-less sudo to chef client as part of an ANT script


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?


Solution

  • 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