Last active
January 4, 2017 06:11
-
-
Save gsmurali/0e80095ad831c3ff86995b64adaa7991 to your computer and use it in GitHub Desktop.
05 Linux Academy - Certified Chef Developer Basic Chef Fluency Badge- Lecture: Applying Chef Resources Hands On
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
[root@gsmurali1 user]# vim learn.rb | |
[root@gsmurali1 user]# cat learn.rb | |
package 'apache' do | |
end | |
This is the pre-convergence checks; to check ruby syntax and chef syntax | |
------------------------------------------------------------------------ | |
[root@gsmurali1 user]# ruby -c learn.rb | |
Syntax OK | |
[root@gsmurali1 user]# 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 | |
In the absence of the package name property the resource name, in our case apache, will be used as the package name. Since we are running on Centos, | |
this should error out. | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-04T05:37:36+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-04T05:37:36+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-04T05:37:49+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 1 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install | |
* No candidate version available for apache | |
================================================================================ | |
Error executing action `install` on resource 'yum_package[apache]' | |
================================================================================ | |
Chef::Exceptions::Package | |
------------------------- | |
No candidate version available for apache | |
Resource Declaration: | |
--------------------- | |
# In /home/user/learn.rb | |
1: package 'apache' do | |
2: end | |
Compiled Resource: | |
------------------ | |
# Declared in /home/user/learn.rb:1:in `from_file' | |
yum_package("apache") do | |
package_name "apache" | |
action [:install] | |
retries 0 | |
retry_delay 2 | |
default_guard_interpreter :default | |
declared_type :package | |
cookbook_name "@recipe_files" | |
recipe_name "/home/user/learn.rb" | |
flush_cache {:before=>false, :after=>false} | |
end | |
Platform: | |
--------- | |
x86_64-linux | |
Running handlers: | |
[2017-01-04T05:38:34+00:00] ERROR: Running exception handlers | |
Running handlers complete | |
[2017-01-04T05:38:34+00:00] ERROR: Exception handlers complete | |
Chef Client failed. 0 resources updated in 56 seconds | |
[2017-01-04T05:38:34+00:00] FATAL: Stacktrace dumped to /root/.chef/local-mode-cache/cache/chef-stacktrace.out | |
[2017-01-04T05:38:34+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report | |
[2017-01-04T05:38:34+00:00] ERROR: yum_package[apache] (@recipe_files::/home/user/learn.rb line 1) had an error: Chef::Exceptions::Package: No candidate version available for apache | |
[2017-01-04T05:38:34+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) | |
[root@gsmurali1 user]# | |
Fix the error | |
------------- | |
[root@gsmurali1 user]# cat learn.rb | |
package 'apache' do | |
package_name 'httpd' | |
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-04T05:43:10+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-04T05:43:10+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-04T05:43:15+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 1 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install | |
- install version 2.4.6-45.el7.centos of package httpd | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 1/1 resources updated in 26 seconds | |
[root@gsmurali1 user]# systemctl status httpd | |
● httpd.service - The Apache HTTP Server | |
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) | |
Active: inactive (dead) | |
Docs: man:httpd(8) | |
man:apachectl(8) | |
[root@gsmurali1 user]# | |
After including the service actions | |
------------------------------------- | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-04T05:48:20+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-04T05:48:20+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-04T05:48:24+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 2 resources | |
Recipe: @recipe_files::/home/user/learn.rb | |
* yum_package[apache] action install (up to date) | |
* service[httpd] action enable | |
- enable service service[httpd] | |
* service[httpd] action start | |
- start service service[httpd] | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 2/3 resources updated in 08 seconds | |
[root@gsmurali1 user]# | |
Adding a File resource | |
---------------------- | |
[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-04T05:53:58+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-04T05:53:58+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-04T05:54:00+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 3 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 create | |
- create new file /var/www/index.html | |
- restore selinux security context | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 1/4 resources updated in 06 seconds | |
[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 | |
end | |
[root@gsmurali1 user]# | |
Updating index.html | |
------------------- | |
[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 | |
[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-04T06:01:45+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-04T06:01:45+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-04T06:01:47+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 4 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 | |
- delete file /var/www/index.html | |
* file[/var/www/html/index.html] action create | |
- create new file /var/www/html/index.html | |
- update content in file /var/www/html/index.html from none to 7f83b1 | |
--- /var/www/html/index.html 2017-01-04 06:01:52.667158695 +0000 | |
+++ /var/www/html/.chef-index20170104-5911-1572h29.html 2017-01-04 06:01:52.667158695 +0000 | |
@@ -1 +1,2 @@ | |
+Hello World! | |
- change mode from '' to '0755' | |
- change owner from '' to 'root' | |
- change group from '' to 'apache' | |
- restore selinux security context | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 2/5 resources updated in 07 seconds | |
[root@gsmurali1 user]# ls -al /var/www | |
total 4 | |
drwxr-xr-x. 4 root root 31 Jan 4 06:01 . | |
drwxr-xr-x. 22 root root 4096 Jan 4 05:43 .. | |
drwxr-xr-x. 2 root root 6 Nov 14 18:05 cgi-bin | |
drwxr-xr-x. 2 root root 23 Jan 4 06:01 html | |
[root@gsmurali1 user]# ls -al /var/www/html | |
total 4 | |
drwxr-xr-x. 2 root root 23 Jan 4 06:01 . | |
drwxr-xr-x. 4 root root 31 Jan 4 06:01 .. | |
-rwxr-xr-x. 1 root apache 12 Jan 4 06:01 index.html | |
[root@gsmurali1 user]# | |
Chef remembers the contents of the file using the checksum. So even if the file is updated outside chef, at the time of convergence chef identifies it and replaces the contents | |
[root@gsmurali1 user]# chef-client --local-mode learn.rb | |
[2017-01-04T06:08:16+00:00] WARN: No config file found or specified on command line, using command line options. | |
[2017-01-04T06:08:16+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-04T06:08:18+00:00] WARN: Node gsmurali1.mylabserver.com has an empty run list. | |
Converging 4 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 | |
- update content in file /var/www/html/index.html from b0bf55 to 7f83b1 | |
--- /var/www/html/index.html 2017-01-04 06:07:34.391684354 +0000 | |
+++ /var/www/html/.chef-index20170104-6333-s7zp9t.html 2017-01-04 06:08:23.037043888 +0000 | |
@@ -1,3 +1,2 @@ | |
-This is the updated version | |
Hello World! | |
- restore selinux security context | |
Running handlers: | |
Running handlers complete | |
Chef Client finished, 1/5 resources updated in 06 seconds | |
[root@gsmurali1 user]# | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment