Last active
January 8, 2017 01:51
-
-
Save gsmurali/c45fa1913ef9ef5b79ba78df057e0272 to your computer and use it in GitHub Desktop.
06 Linux Academy - Certified Chef Developer Basic Chef Fluency Badge- Lecture: Working with not_if and only_if Guards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+Terminal log: | |
C:\Users\shinidharan\Documents\GitHub> ssh [email protected] | |
Warning: Permanently added '54.86.131.236' (ECDSA) to the list of known hosts | |
[email protected]'s password: | |
Last login: Wed Jan 4 05:06:13 2017 from c-76-104-43-10.hsd1.va.comcast.net | |
[user@gsmurali1 ~]$ vim learn.rb | |
[user@gsmurali1 ~]$ cat learn.rb | |
package 'apache' do | |
package_name 'httpd' | |
end | |
service 'httpd' do | |
action [:enable, :start] | |
end | |
file '/var/www/index.html' do | |
action :delete | |
end | |
file '/var/www/html/index.html' do | |
content 'Hello World!' | |
mode '0755' | |
owner 'root' | |
group 'apache' | |
end | |
file '/etc/motd' do | |
content 'Welcome to my server' | |
end | |
[user@gsmurali1 ~]$ ruby -c learn.rb | |
Syntax OK | |
[user@gsmurali1 ~]$ foodcritic learn.rb | |
FC011: Missing README in markdown format: ../README.md:1 | |
FC031: Cookbook without metadata file: ../metadata.rb:1 | |
FC045: Metadata does not contain cookbook name: ../metadata.rb:1 | |
[user@gsmurali1 ~]$ sudo su | |
[sudo] password for user: | |
Sorry, try again. | |
[sudo] password for user: | |
[root@gsmurali1 user]# clear | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-05T05:16:05+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-05T05:16:05+00:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/user. | |
Starting Chef Client, version 12.17.44 | |
resolving cookbooks for run list: [] | |
Synchronizing Cookbooks: | |
Installing Cookbook Gems: | |
Compiling Cookbooks... | |
[2017-01-05T05:16:07+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 5 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install (up to date) | |
* service[httpd] action enable (up to date) | |
* service[httpd] action start (up to date) | |
* file[/var/www/index.html] action delete (up to date) | |
* file[/var/www/html/index.html] action create (up to date) | |
* file[/etc/motd] action create | |
- update content in file /etc/motd from e3b0c4 to ba4ed8 | |
--- /etc/motd 2013-06-07 14:31:32.000000000 +0000 | |
+++ /etc/.chef-motd20170105-1911-1jq9nop 2017-01-05 05:16:16.142880029 +0000 | |
@@ -1 +1,2 @@ | |
+Welcome to my server | |
- restore selinux security context | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 1/6 resources updated in 10 seconds | |
[root@gsmurali1 user]# cat /etc/motd | |
Welcome to my server[root@gsmurali1 user]# | |
[user@gsmurali1 ~]$ cat learn.rb | |
package 'apache' do | |
package_name 'httpd' | |
end | |
service 'httpd' do | |
action [:enable, :start] | |
end | |
file '/var/www/index.html' do | |
action :delete | |
end | |
file '/var/www/html/index.html' do | |
content 'Hello World!' | |
mode '0755' | |
owner 'root' | |
group 'apache' | |
end | |
file '/etc/motd' do | |
content 'Welcome to my server' | |
end | |
execute 'command-test' do | |
command 'echo blah >> /etc/motd' | |
only_if 'test -r /etc/motd' | |
end | |
[user@gsmurali1 ~]$ ruby -c learn.rb && foodcritic learn.rb | |
Syntax OK | |
FC011: Missing README in markdown format: ../README.md:1 | |
FC031: Cookbook without metadata file: ../metadata.rb:1 | |
FC045: Metadata does not contain cookbook name: ../metadata.rb:1 | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-05T05:23:44+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-05T05:23:44+00:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/user. | |
Starting Chef Client, version 12.17.44 | |
resolving cookbooks for run list: [] | |
Synchronizing Cookbooks: | |
Installing Cookbook Gems: | |
Compiling Cookbooks... | |
[2017-01-05T05:23:46+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 6 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install (up to date) | |
* service[httpd] action enable (up to date) | |
* service[httpd] action start (up to date) | |
* file[/var/www/index.html] action delete (up to date) | |
* file[/var/www/html/index.html] action create (up to date) | |
* file[/etc/motd] action create (up to date) | |
* execute[command-test] action run | |
- execute echo blah >> /etc/motd | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 1/7 resources updated in 09 seconds | |
[root@gsmurali1 user]# cat /etc/motd | |
Welcome to my serverblah | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-05T05:25:53+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-05T05:25:53+00:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/user. | |
Starting Chef Client, version 12.17.44 | |
resolving cookbooks for run list: [] | |
Synchronizing Cookbooks: | |
Installing Cookbook Gems: | |
Compiling Cookbooks... | |
[2017-01-05T05:25:56+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 6 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install (up to date) | |
* service[httpd] action enable (up to date) | |
* service[httpd] action start (up to date) | |
* file[/var/www/index.html] action delete (up to date) | |
* file[/var/www/html/index.html] action create (up to date) | |
* file[/etc/motd] action create | |
- update content in file /etc/motd from 0292b5 to ba4ed8 | |
--- /etc/motd 2017-01-05 05:23:53.810537856 +0000 | |
+++ /etc/.chef-motd20170105-3059-1m236p9 2017-01-05 05:26:00.672747697 +0000 | |
@@ -1,2 +1,2 @@ | |
-Welcome to my serverblah | |
+Welcome to my server | |
- restore selinux security context | |
* execute[command-test] action run | |
- execute echo blah >> /etc/motd | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 2/7 resources updated in 06 seconds | |
[root@gsmurali1 user]# cat /etc/motd | |
Welcome to my serverblah | |
[root@gsmurali1 user]# | |
[root@gsmurali1 user]# cat learn.rb | |
package 'apache' do | |
package_name 'httpd' | |
end | |
service 'httpd' do | |
action [:enable, :start] | |
end | |
file '/var/www/index.html' do | |
action :delete | |
end | |
file '/var/www/html/index.html' do | |
content 'Hello World!' | |
mode '0755' | |
owner 'root' | |
group 'apache' | |
end | |
#file '/etc/motd' do | |
# content 'Welcome to my server' | |
# | |
#end | |
execute 'command-test' do | |
command 'echo blah >> /etc/motd' | |
only_if 'test -r /etc/motd' | |
end | |
[root@gsmurali1 user]# ruby -c learn.rb && foodcritic learn.rb | |
Syntax OK | |
FC011: Missing README in markdown format: ../README.md:1 | |
FC031: Cookbook without metadata file: ../metadata.rb:1 | |
FC045: Metadata does not contain cookbook name: ../metadata.rb:1 | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-05T05:29:29+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-05T05:29:29+00:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/user. | |
Starting Chef Client, version 12.17.44 | |
resolving cookbooks for run list: [] | |
Synchronizing Cookbooks: | |
Installing Cookbook Gems: | |
Compiling Cookbooks... | |
[2017-01-05T05:29:31+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 5 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install (up to date) | |
* service[httpd] action enable (up to date) | |
* service[httpd] action start (up to date) | |
* file[/var/www/index.html] action delete (up to date) | |
* file[/var/www/html/index.html] action create (up to date) | |
* execute[command-test] action run | |
- execute echo blah >> /etc/motd | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 1/6 resources updated in 06 seconds | |
[root@gsmurali1 user]# cat /etc/motd | |
Welcome to my serverblah | |
blah | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-05T05:29:48+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-05T05:29:48+00:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/user. | |
Starting Chef Client, version 12.17.44 | |
resolving cookbooks for run list: [] | |
Synchronizing Cookbooks: | |
Installing Cookbook Gems: | |
Compiling Cookbooks... | |
[2017-01-05T05:29:50+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 5 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install (up to date) | |
* service[httpd] action enable (up to date) | |
* service[httpd] action start (up to date) | |
* file[/var/www/index.html] action delete (up to date) | |
* file[/var/www/html/index.html] action create (up to date) | |
* execute[command-test] action run | |
- execute echo blah >> /etc/motd | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 1/6 resources updated in 05 seconds | |
[root@gsmurali1 user]# cat /etc/motd | |
Welcome to my serverblah | |
blah | |
blah | |
[root@gsmurali1 user]# | |
[root@gsmurali1 user]# rm /etc/motd | |
rm: remove regular file ‘/etc/motd’? y | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-05T05:32:29+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-05T05:32:29+00:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/user. | |
Starting Chef Client, version 12.17.44 | |
resolving cookbooks for run list: [] | |
Synchronizing Cookbooks: | |
Installing Cookbook Gems: | |
Compiling Cookbooks... | |
[2017-01-05T05:32:31+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 5 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install (up to date) | |
* service[httpd] action enable (up to date) | |
* service[httpd] action start (up to date) | |
* file[/var/www/index.html] action delete (up to date) | |
* file[/var/www/html/index.html] action create (up to date) | |
* execute[command-test] action run (skipped due to only_if) | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 0/6 resources updated in 06 seconds | |
[root@gsmurali1 user]# | |
[root@gsmurali1 user]# cat learn.rb | |
package 'apache' do | |
package_name 'httpd' | |
end | |
service 'httpd' do | |
action [:enable, :start] | |
end | |
file '/var/www/index.html' do | |
action :delete | |
end | |
file '/var/www/html/index.html' do | |
content 'Hello World!' | |
mode '0755' | |
owner 'root' | |
group 'apache' | |
end | |
#file '/etc/motd' do | |
# content 'Welcome to my server' | |
# | |
#end | |
#execute 'command-test' do | |
# command 'echo blah >> /etc/motd' | |
# only_if 'test -r /etc/motd' | |
#end | |
execute 'command-test' do | |
command 'echo blah >> /etc/motd' | |
not_if 'test -r /etc/motd' | |
end | |
[root@gsmurali1 user]# ruby -c learn.rb && foodcritic learn.rb | |
Syntax OK | |
FC011: Missing README in markdown format: ../README.md:1 | |
FC031: Cookbook without metadata file: ../metadata.rb:1 | |
FC045: Metadata does not contain cookbook name: ../metadata.rb:1 | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-05T05:36:40+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-05T05:36:40+00:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/user | |
Starting Chef Client, version 12.17.44 | |
resolving cookbooks for run list: [] | |
Synchronizing Cookbooks: | |
Installing Cookbook Gems: | |
Compiling Cookbooks... | |
[2017-01-05T05:36:42+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 5 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install (up to date) | |
* service[httpd] action enable (up to date) | |
* service[httpd] action start (up to date) | |
* file[/var/www/index.html] action delete (up to date) | |
* file[/var/www/html/index.html] action create (up to date) | |
* execute[command-test] action run | |
- execute echo blah >> /etc/motd | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 1/6 resources updated in 06 seconds | |
[root@gsmurali1 user]# touch /etc/motd | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-05T05:37:37+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-05T05:37:37+00:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/user | |
Starting Chef Client, version 12.17.44 | |
resolving cookbooks for run list: [] | |
Synchronizing Cookbooks: | |
Installing Cookbook Gems: | |
Compiling Cookbooks... | |
[2017-01-05T05:37:39+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 5 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install (up to date) | |
* service[httpd] action enable (up to date) | |
* service[httpd] action start (up to date) | |
* file[/var/www/index.html] action delete (up to date) | |
* file[/var/www/html/index.html] action create (up to date) | |
* execute[command-test] action run (skipped due to not_if) | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 0/6 resources updated in 05 seconds | |
[root@gsmurali1 user]# | |
[root@gsmurali1 user]# cat /etc/motd | |
blah | |
[root@gsmurali1 user]# ruby -c learn.rb && foodcritic learn.rb | |
learn.rb:37: syntax error, unexpected '}', expecting ')' | |
[root@gsmurali1 user]# vim learn.rb | |
[root@gsmurali1 user]# cat learn.rb | |
package 'apache' do | |
package_name 'httpd' | |
end | |
service 'httpd' do | |
action [:enable, :start] | |
end | |
file '/var/www/index.html' do | |
action :delete | |
end | |
file '/var/www/html/index.html' do | |
content 'Hello World!' | |
mode '0755' | |
owner 'root' | |
group 'apache' | |
end | |
#file '/etc/motd' do | |
# content 'Welcome to my server' | |
# | |
#end | |
#execute 'command-test' do | |
# command 'echo blah >> /etc/motd' | |
# only_if 'test -r /etc/motd' | |
#end | |
#execute 'command-test' do | |
# command 'echo blah >> /etc/motd' | |
# not_if 'test -r /etc/motd' | |
#end | |
execute 'command-test' do | |
command 'echo blah >> /etc/motd' | |
only_if { File.exists?('/etc/motd') } | |
end | |
[root@gsmurali1 user]# ruby -c learn.rb && foodcritic learn.rb | |
Syntax OK | |
FC011: Missing README in markdown format: ../README.md:1 | |
FC031: Cookbook without metadata file: ../metadata.rb:1 | |
FC045: Metadata does not contain cookbook name: ../metadata.rb:1 | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-05T05:44:37+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-05T05:44:37+00:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/user. | |
Starting Chef Client, version 12.17.44 | |
resolving cookbooks for run list: [] | |
Synchronizing Cookbooks: | |
Installing Cookbook Gems: | |
Compiling Cookbooks... | |
[2017-01-05T05:44:39+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 5 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install (up to date) | |
* service[httpd] action enable (up to date) | |
* service[httpd] action start (up to date) | |
* file[/var/www/index.html] action delete (up to date) | |
* file[/var/www/html/index.html] action create (up to date) | |
* execute[command-test] action run | |
- execute echo blah >> /etc/motd | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 1/6 resources updated in 06 seconds | |
[root@gsmurali1 user]# cat /etc/motd | |
blah | |
blah | |
[root@gsmurali1 user]# | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment