Error on command 'chef generate cookbook motd'

Hi community,

I am new to Chef.
When I execute the command chef generate cookbook motd on Chef-DK running on RHEL 7 referring to Learning Chef issued by O’REILLY, some errors occurred as shown below. Seems like they are relevant to accessing Git. But I can see the child directories have been created (as you can see the end of this posting). Could someone advise what happened at the moment and if there was something I needed to do prior to executing the command? Are these errors negligible?

Here’s the version of Chef-DK,
chefdk-1.0.3-1.el7.x86_64

Thank you in advance!

  • Nakmark

    [root@DEMOCHEFDK learningchef]# chef generate cookbook motd
    Generating cookbook motd

    • Ensuring correct cookbook file content
    • Committing cookbook files to git

    ================================================================================
    Error executing action run on resource ‘execute[git-commit-new-files]’

    Mixlib::ShellOut::ShellCommandFailed

    Expected process to exit with [0], but received ‘128’
    ---- Begin output of git commit -m “Add generated cookbook content” ----
    STDOUT:
    STDERR: *** Please tell me who you are.

    Run

    git config --global user.email "you@example.com"
    git config --global user.name “Your Name”

    to set your account’s default identity.
    Omit --global to set the identity only in this repository.

    fatal: unable to auto-detect email address (got ‘root@DEMOCHEFDK.(none)’)
    ---- End output of git commit -m “Add generated cookbook content” ----
    Ran git commit -m “Add generated cookbook content” returned 128

    Resource Declaration:

    In /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/chef-dk-1.0.3/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb

    124: execute(“git-commit-new-files”) do
    125: command(“git commit -m “Add generated cookbook content””)
    126: cwd cookbook_dir
    127: end
    128: end

    Compiled Resource:

    Declared in /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/chef-dk-1.0.3/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb:124:in `from_file’

    execute(“git-commit-new-files”) do
    action [:run]
    retries 0
    retry_delay 2
    default_guard_interpreter :execute
    command "git commit -m “Add generated cookbook content”"
    backup 5
    cwd "/learningchef/motd"
    returns 0
    declared_type :execute
    cookbook_name :code_generator
    recipe_name "cookbook"
    end

    Platform:

    x86_64-linux

    ERROR: Chef failed to converge: execute[git-commit-new-files] (code_generator::cookbook line 124) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘128’
    ---- Begin output of git commit -m “Add generated cookbook content” ----
    STDOUT:
    STDERR: *** Please tell me who you are.

    Run

    git config --global user.email "you@example.com"
    git config --global user.name “Your Name”

    to set your account’s default identity.
    Omit --global to set the identity only in this repository.

    fatal: unable to auto-detect email address (got ‘root@DEMOCHEFDK.(none)’)
    ---- End output of git commit -m “Add generated cookbook content” ----
    Ran git commit -m “Add generated cookbook content” returned 128
    Caused by: (Mixlib::ShellOut::ShellCommandFailed) execute[git-commit-new-files] (code_generator::cookbook line 124) had an error: Mixlib::ShellOut::ShellCommandFailed : Expected process to exit with [0], but received ‘128’
    ---- Begin output of git commit -m “Add generated cookbook content” ----
    STDOUT:
    STDERR: *** Please tell me who you are.

    Run

    git config --global user.email "you@example.com"
    git config --global user.name “Your Name”

    to set your account’s default identity.
    Omit --global to set the identity only in this repository.

    fatal: unable to auto-detect email address (got ‘root@DEMOCHEFDK.(none)’)
    ---- End output of git commit -m “Add generated cookbook content” ----
    Ran git commit -m “Add generated cookbook content” returned 128
    [root@DEMOCHEFDK learningchef]# echo $?
    1

    [root@DEMOCHEFDK motd]# ls -R
    .:
    Berksfile README.md chefignore metadata.rb recipes spec test

    ./recipes:
    default.rb

    ./spec:
    spec_helper.rb unit

    ./spec/unit:
    recipes

    ./spec/unit/recipes:
    default_spec.rb

    ./test:
    recipes

    ./test/recipes:
    default_test.rb

It looks like your only issue is that your git configuration is not yet complete on your RHEL 7 workstation. Have your tried running the two git config commands suggested in the output? I believe that without these entries, git will complain each time you try to do a commit. It will perform the commit based upon your machine hostname, but I believe that you will continue to receive these “warnings.”

Resolved! Thank you so much for your advise Byteflyer!
After executing the two commands for setting up git, the command chef generate cookbook motd worked as intended as below. (I found what those commands are described in https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup .)
By the way, the first edition of O’REILLY’s released on Nov 2014 doesn’t seem to cover the process.

Again, thank you for your great help!

  • Nakmark

    [root@DEMOCHEFDK learningchef]# chef generate cookbook motd
    Generating cookbook motd

    • Ensuring correct cookbook file content
    • Ensuring delivery configuration
    • Ensuring correct delivery build cookbook content

    Your cookbook is ready. Type cd motd to enter it.

    There are several commands you can run to get started locally developing and testing your cookbook.
    Type delivery local --help to see a full list.

    Why not start by writing a test? Tests for the default recipe are stored at:

    test/recipes/default_test.rb

    If you’d prefer to dive right in, the default recipe can be found at:

    recipes/default.rb

    [root@DEMOCHEFDK learningchef]# echo $?
    0

    [root@DEMOCHEFDK learningchef]# ls -R ./motd/
    ./motd/:
    Berksfile README.md chefignore metadata.rb recipes spec test

    ./motd/recipes:
    default.rb

    ./motd/spec:
    spec_helper.rb unit

    ./motd/spec/unit:
    recipes

    ./motd/spec/unit/recipes:
    default_spec.rb

    ./motd/test:
    recipes

    ./motd/test/recipes:
    default_test.rb