LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-06-2017, 03:38 PM   #1
johnpedou
LQ Newbie
 
Registered: Dec 2016
Posts: 17

Rep: Reputation: Disabled
Changing Directories in Chef Recipe


This is my first attempt at writing a chef cookbook. I'm attempting to write a recipe that will automatically install git, make a new directory (git_repo), change to that directory, initialize to be a git repository, and then connect to the remote git repository once I run chef-client on my node. I got it to install git and make the directory but I am unsure how to write within the recipe to change directory to git_repo. the code I have is

Quote:
package 'git' do
action :install
end

directory '/home/git_repo' do
mode 0755
owner 'root'
group 'root'
action :create
end

execute 'change' do
command "sudo cd git_repo"
end
Is there a better resource type to use besides execute for this particular action? If so, could someone elaborate on it?
 
Old 01-10-2017, 11:17 PM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,861
Blog Entries: 36

Rep: Reputation: 459Reputation: 459Reputation: 459Reputation: 459Reputation: 459
Why do you need to run the cd command? Many of Chef's commands offer a cwd (i.e. Current working directory) option. Why can't you use that?

Here's an example.

Code:
bash 'extract_module' do
  cwd '/home/git_repo'
  code <<-EOH
    git init
    git remote add origin some_url
    git fetch origin
    git reset --hard origin/master
    EOH
end
See https://docs.chef.io/resource_bash.html

Last edited by sag47; 01-10-2017 at 11:27 PM.
 
1 members found this post helpful.
Old 01-10-2017, 11:37 PM   #3
johnpedou
LQ Newbie
 
Registered: Dec 2016
Posts: 17

Original Poster
Rep: Reputation: Disabled
Well it was the first time I was writing a cookbook and I did end up using cwd. That's why I marked the post as solved. Regardless, thank you for the help.
 
Old 01-11-2017, 01:41 PM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,861
Blog Entries: 36

Rep: Reputation: 459Reputation: 459Reputation: 459Reputation: 459Reputation: 459
Glad you figured it out. Perhaps post your solution when you solve it so others can benefit. After rereading my original reply it came off a bit terse. That was not my intent.

Last edited by sag47; 01-11-2017 at 01:43 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Changing directories darkmouse Linux - Newbie 3 10-08-2012 03:40 PM
changing home directories help autotron Linux - Newbie 4 05-01-2012 04:02 PM
Changing directories in Sabayon. mwarwick Linux - Newbie 1 03-23-2008 07:23 PM
changing permissions only for directories xpucto Linux - Newbie 2 03-11-2007 05:09 AM
Changing Permissions on Directories... bob4432 Linux - Newbie 6 06-25-2004 02:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration