While we writing this cookbook we have used the same resource with different values multiple times
apt_package 'apache2' do
# sudo apt install php libapache2-mod-php php-mysql -y
apt_package 'php' do
apt_package 'libapache2-mod-php' do
apt_package 'php-mysql' do
# sudo apt install php-cli -y
apt_package 'php-cli' do
So now lets correlate this situation with some basic programming
names = ['apache2', 'php', 'php-mysql']
for(name in names):
Generally we use approach 2 as writing number of lines of print doesn’t make sense
So, should we not apply same approach for our recipe in chef
In chef, if we have to use the better way, lets try to understand little bit of ruby.
Just Enough Ruby for Chef. Refer Here for chef docs on Ruby.
Test Driven Development of Chef cookbooks using test kitchen.