Pergunta

I've tried this a couple different ways, including creating a new recipe and notifying that recipe to run but I keep getting the same problem which is the cloned repo directory doesn't exist before the file resource runs, so I get a fatal error.

my question is, can I make the git clone finish before the file resource tries to execute or is there a better way to do this?

SN: what I'm trying to accomplish deals w/ new user environment setup - so after creating a new user i'm cloning down a bunch of config files from a git repo that will be deployed for that user.

  git "/home/#{user_id}/.myconfigs" do
    repository "https://url/to/repo"
    reference "master"
    user user_id
    group user_id
    action :checkout
    not_if "test -d /home/#{user_id}/.myconfigs"
    #notifies :run, "recipe[zsh_workstation::zshrc]"
  end

  file "/home/#{user_id}/.zshrc" do
    content IO.read("/home/#{user_id}/.myconfigs/.zshrc")
    owner user_id
    group user_id
    mode "0600"
    action :create_if_missing
  end
Foi útil?

Solução

Check Anatomy of a Chef Run

At the moment chef compiles your file resource, git resource is not run (even is not started) yet, so file "/home/#{user_id}/.myconfigs/.zshrc" does not exist.

Possible workarounds:

  1. This will copy the file after it is created by git using FileUtils.

    ruby_block "create /home/#{user_id}/.zshrc" do
      block do
        ::FileUtils.copy("/home/#{user_id}/.myconfigs/.zshrc", "/home/#{user_id} /.zshrc") unless ::File.exists? "/home/#{user_id}/.zshrc" 
      end
    end
    
  2. Symlink instead of copy.

    link "/home/#{user_id}/.zshrc" do
      to "/home/#{user_id}/.myconfigs/.zshrc"
    end
    
  3. Run git resource at compile stage.

    git "/home/#{user_id}/.myconfigs" do
      [...]
      action :nothing
    end.run_action :checkout
    
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top