diff --git a/1_MongoDB/MongoDb-install-unsucessfullRuns.txt b/1_MongoDB/MongoDb-install-unsucessfullRuns.txt new file mode 100644 index 0000000..9a7fe38 --- /dev/null +++ b/1_MongoDB/MongoDb-install-unsucessfullRuns.txt @@ -0,0 +1,331 @@ +root@osboxes recipes]# chef-client --local-mode install.rb +[2018-02-10T20:04:43-05:00] WARN: No config file found or specified on command line, using command line options. +Starting Chef Client, version 13.6.4 +resolving cookbooks for run list: ["learn_chef_httpd"] +Synchronizing Cookbooks: + - learn_chef_httpd (0.1.0) +Installing Cookbook Gems: +Compiling Cookbooks... + +Running handlers: +[2018-02-10T20:04:48-05:00] ERROR: Running exception handlers +[2018-02-10T20:04:48-05:00] ERROR: Running exception handlers +Running handlers complete +[2018-02-10T20:04:48-05:00] ERROR: Exception handlers complete +[2018-02-10T20:04:48-05:00] ERROR: Exception handlers complete +Chef Client failed. 0 resources updated in 04 seconds +[2018-02-10T20:04:48-05:00] FATAL: Stacktrace dumped to /root/.chef/local-mode-cache/cache/chef-stacktrace.out +[2018-02-10T20:04:48-05:00] FATAL: Stacktrace dumped to /root/.chef/local-mode-cache/cache/chef-stacktrace.out +[2018-02-10T20:04:48-05:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report +[2018-02-10T20:04:48-05:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report +[2018-02-10T20:04:48-05:00] ERROR: Option action must be equal to one of: nothing, install, upgrade, remove, purge, reconfig, lock, unlock! You passed :start. +[2018-02-10T20:04:48-05:00] ERROR: Option action must be equal to one of: nothing, install, upgrade, remove, purge, reconfig, lock, unlock! You passed :start. +[2018-02-10T20:04:48-05:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) +[2018-02-10T20:04:48-05:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) +[root@osboxes recipes]# chef-client --local-mode install.rb +[2018-02-10T20:07:03-05:00] WARN: No config file found or specified on command line, using command line options. +Starting Chef Client, version 13.6.4 +resolving cookbooks for run list: ["learn_chef_httpd"] +Synchronizing Cookbooks: + - learn_chef_httpd (0.1.0) +Installing Cookbook Gems: +Compiling Cookbooks... +Converging 5 resources +Recipe: learn_chef_httpd::default + * yum_package[httpd] action install^[[A^[[A (up to date) + * service[httpd] action enable (up to date) + * service[httpd] action start (up to date) + * template[/var/www/html/index.html] action create (up to date) +Recipe: @recipe_files::/chef-repo/cookbooks/mongodb/recipes/install.rb + * yum_repository[mongodb] action create + * template[/etc/yum.repos.d/mongodb.repo] action create + - update content in file /etc/yum.repos.d/mongodb.repo from e3b0c4 to acded2 + --- /etc/yum.repos.d/mongodb.repo 2018-02-10 01:03:23.942774971 -0500 + +++ /etc/yum.repos.d/.chef-mongodb20180210-16941-w8avo5.repo 2018-02-10 20:07:22.730208840 -0500 + @@ -1 +1,9 @@ + +# This file was generated by Chef + +# Do NOT modify this file by hand. + + + +[mongodb] + +name=MongoDB Repository + +enabled=1 + +fastestmirror_enabled=0 + +gpgcheck=0^[[B + - restore selinux security context + * execute[yum clean metadata mongodb] action run + - execute yum clean metadata --disablerepo=* --enablerepo=mongodb + * execute[yum-makecache-mongodb] action run + + ================================================================================ + Error executing action `run` on resource 'execute[yum-makecache-mongodb]' + ================================================================================ + + Mixlib::ShellOut::ShellCommandFailed + ------------------------------------ + Expected process to exit with [0], but received '1' + ---- Begin output of yum -q -y makecache --disablerepo=* --enablerepo=mongodb ---- + STDOUT: + STDERR: One of the configured repositories failed (Unknown), + and yum doesn't have enough cached data to continue. At this point the only + safe thing yum can do is fail. There are a few ways to work "fix" this: + + 1. Contact the upstream for the repository and get them to fix the problem. + + 2. Reconfigure the baseurl/etc. for the repository, to point to a working + upstream. This is most often useful if you are using a newer + distribution release than is supported by the repository (and the + packages for the previous distribution release still work). + + 3. Run the command with the repository temporarily disabled + yum --disablerepo= ... + + 4. Disable the repository permanently, so yum won't use it by default. Yum + will then just ignore the repository until you permanently enable it + again or use --enablerepo for temporary usage: + + yum-config-manager --disable + or + subscription-manager repos --disable= + + 5. Configure the failing repository to be skipped, if it is unavailable. + Note that yum will try to contact the repo. when it runs most commands, + so will have to try and fail each time (and thus. yum will be be much + slower). If it is a very temporary problem though, this is often a nice + compromise: + + yum-config-manager --save --setopt=.skip_if_unavailable=true + + Cannot find a valid baseurl for repo: mongodb + ---- End output of yum -q -y makecache --disablerepo=* --enablerepo=mongodb ---- + Ran yum -q -y makecache --disablerepo=* --enablerepo=mongodb returned 1 + + Resource Declaration: + --------------------- + # In /opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/provider/yum_repository.rb + + 60: declare_resource(:execute, "yum-makecache-#{new_resource.repositoryid}") do + 61: command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}" + 62: action :nothing + 63: only_if { new_resource.enabled } + 64: end + 65: + + Compiled Resource: + ------------------ + # Declared in /opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/provider/yum_repository.rb:60:in `block in ' + + execute("yum-makecache-mongodb") do + action [:nothing] + default_guard_interpreter :execute + command "yum -q -y makecache --disablerepo=* --enablerepo=mongodb" + backup 5 + returns 0 + user nil + declared_type :execute + cookbook_name "@recipe_files" + domain nil + only_if { #code block } + end + + System Info: + ------------ + chef_version=13.6.4 + platform=centos + platform_version=7.4.1708 + ruby=ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux] + program_name=chef-client worker: ppid=16936;start=20:07:03; + executable=/opt/chefdk/bin/chef-client + + + ================================================================================ + Error executing action `create` on resource 'yum_repository[mongodb]' + ================================================================================ + + Mixlib::ShellOut::ShellCommandFailed + ------------------------------------ + execute[yum-makecache-mongodb] (/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/provider/yum_repository.rb line 60) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1' + ---- Begin output of yum -q -y makecache --disablerepo=* --enablerepo=mongodb ---- + STDOUT: + STDERR: One of the configured repositories failed (Unknown), + and yum doesn't have enough cached data to continue. At this point the only + safe thing yum can do is fail. There are a few ways to work "fix" this: + + 1. Contact the upstream for the repository and get them to fix the problem. + + 2. Reconfigure the baseurl/etc. for the repository, to point to a working + upstream. This is most often useful if you are using a newer + distribution release than is supported by the repository (and the + packages for the previous distribution release still work). + + 3. Run the command with the repository temporarily disabled + yum --disablerepo= ... + + 4. Disable the repository permanently, so yum won't use it by default. Yum + will then just ignore the repository until you permanently enable it + again or use --enablerepo for temporary usage: + + yum-config-manager --disable + or + subscription-manager repos --disable= + + 5. Configure the failing repository to be skipped, if it is unavailable. + Note that yum will try to contact the repo. when it runs most commands, + so will have to try and fail each time (and thus. yum will be be much + slower). If it is a very temporary problem though, this is often a nice + compromise: + + yum-config-manager --save --setopt=.skip_if_unavailable=true + + Cannot find a valid baseurl for repo: mongodb + ---- End output of yum -q -y makecache --disablerepo=* --enablerepo=mongodb ---- + Ran yum -q -y makecache --disablerepo=* --enablerepo=mongodb returned 1 + + Resource Declaration: + --------------------- + # In /chef-repo/cookbooks/mongodb/recipes/install.rb + + 1: yum_repository 'mongodb' do + 2: description 'MongoDB Repository' + 3: baseurl= "http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/" + 4: gpgcheck false + 5: enabled true + 6: action :create + 7: end + 8: + + Compiled Resource: + ------------------ + # Declared in /chef-repo/cookbooks/mongodb/recipes/install.rb:1:in `from_file' + + yum_repository("mongodb") do + action [:create] + updated true + updated_by_last_action true + default_guard_interpreter :default + declared_type :yum_repository + cookbook_name "@recipe_files" + recipe_name "/chef-repo/cookbooks/mongodb/recipes/install.rb" + description "MongoDB Repository" + gpgcheck false + enabled true + repositoryid "mongodb" + end + + System Info: + ------------ + chef_version=13.6.4 + platform=centos + platform_version=7.4.1708 + ruby=ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux] + program_name=chef-client worker: ppid=16936;start=20:07:03; + executable=/opt/chefdk/bin/chef-client + + +Running handlers: +[2018-02-10T20:07:23-05:00] ERROR: Running exception handlers +[2018-02-10T20:07:23-05:00] ERROR: Running exception handlers +Running handlers complete +[2018-02-10T20:07:23-05:00] ERROR: Exception handlers complete +[2018-02-10T20:07:23-05:00] ERROR: Exception handlers complete +Chef Client failed. 2 resources updated in 20 seconds +[2018-02-10T20:07:23-05:00] FATAL: Stacktrace dumped to /root/.chef/local-mode-cache/cache/chef-stacktrace.out +[2018-02-10T20:07:23-05:00] FATAL: Stacktrace dumped to /root/.chef/local-mode-cache/cache/chef-stacktrace.out +[2018-02-10T20:07:23-05:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report +[2018-02-10T20:07:23-05:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report +[2018-02-10T20:07:23-05:00] ERROR: yum_repository[mongodb] (@recipe_files::/chef-repo/cookbooks/mongodb/recipes/install.rb line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: execute[yum-makecache-mongodb] (/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/provider/yum_repository.rb line 60) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1' +---- Begin output of yum -q -y makecache --disablerepo=* --enablerepo=mongodb ---- +STDOUT: +STDERR: One of the configured repositories failed (Unknown), + and yum doesn't have enough cached data to continue. At this point the only + safe thing yum can do is fail. There are a few ways to work "fix" this: + + 1. Contact the upstream for the repository and get them to fix the problem. + + 2. Reconfigure the baseurl/etc. for the repository, to point to a working + upstream. This is most often useful if you are using a newer + distribution release than is supported by the repository (and the + packages for the previous distribution release still work). + + 3. Run the command with the repository temporarily disabled + yum --disablerepo= ... + + 4. Disable the repository permanently, so yum won't use it by default. Yum + will then just ignore the repository until you permanently enable it + again or use --enablerepo for temporary usage: + + yum-config-manager --disable + or + subscription-manager repos --disable= + + 5. Configure the failing repository to be skipped, if it is unavailable. + Note that yum will try to contact the repo. when it runs most commands, + so will have to try and fail each time (and thus. yum will be be much + slower). If it is a very temporary problem though, this is often a nice + compromise: + + yum-config-manager --save --setopt=.skip_if_unavailable=true + +Cannot find a valid baseurl for repo: mongodb +---- End output of yum -q -y makecache --disablerepo=* --enablerepo=mongodb ---- +Ran yum -q -y makecache --disablerepo=* --enablerepo=mongodb returned 1 +[2018-02-10T20:07:23-05:00] ERROR: yum_repository[mongodb] (@recipe_files::/chef-repo/cookbooks/mongodb/recipes/install.rb line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: execute[yum-makecache-mongodb] (/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.6.4/lib/chef/provider/yum_repository.rb line 60) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1' +---- Begin output of yum -q -y makecache --disablerepo=* --enablerepo=mongodb ---- +STDOUT: +STDERR: One of the configured repositories failed (Unknown), + and yum doesn't have enough cached data to continue. At this point the only + safe thing yum can do is fail. There are a few ways to work "fix" this: + + 1. Contact the upstream for the repository and get them to fix the problem. + + 2. Reconfigure the baseurl/etc. for the repository, to point to a working + upstream. This is most often useful if you are using a newer + distribution release than is supported by the repository (and the + packages for the previous distribution release still work). + + 3. Run the command with the repository temporarily disabled + yum --disablerepo= ... + + 4. Disable the repository permanently, so yum won't use it by default. Yum + will then just ignore the repository until you permanently enable it + again or use --enablerepo for temporary usage: + + yum-config-manager --disable + or + subscription-manager repos --disable= + + 5. Configure the failing repository to be skipped, if it is unavailable. + Note that yum will try to contact the repo. when it runs most commands, + so will have to try and fail each time (and thus. yum will be be much + slower). If it is a very temporary problem though, this is often a nice + compromise: + + yum-config-manager --save --setopt=.skip_if_unavailable=true + +Cannot find a valid baseurl for repo: mongodb +---- End output of yum -q -y makecache --disablerepo=* --enablerepo=mongodb ---- +Ran yum -q -y makecache --disablerepo=* --enablerepo=mongodb returned 1 +[2018-02-10T20:07:24-05:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) +[2018-02-10T20:07:24-05:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) + +---------------- +SOLUTION: + +2018-02-11T17:54:34-05:00] WARN: No config file found or specified on command line, using command line options. +[2018-02-11T17:54:35-05:00] WARN: Chef client 10321 is running, will wait for it to finish and then run. +[2018-02-11T17:54:35-05:00] WARN: Chef client 10321 is running, will wait for it to finish and then run. + +[root@osboxes cookbooks]# ps aux | grep chef + +RESULT: +bin/chef-client --local-mode default.rb +root 10658 0.0 1.6 263932 48496 pts/0 Tl 17:32 0:00 chef-client worker: ppid=10653;start=17:32:32; +root 10842 0.0 1.6 263336 47904 ? Sl 17:36 0:00 chef-client worker: ppid=10837;start=17:36:55; +root 11093 0.2 1.7 264508 52840 pts/0 Tl 17:38 0:03 /opt/chefdk/embedded/bin/ruby --disable-gems /usr/bin/chef-client --local-mode default.rb +root 11098 0.0 1.6 264648 49096 pts/0 Tl 17:38 0:00 chef-client worker: ppid=11093;start=17:38:45; +root 11382 0.2 1.7 263312 51624 pts/0 + + +[root@osboxes cookbooks]# sudo kill -9 10321 + + + diff --git a/1_MongoDB/README.md b/1_MongoDB/README.md index 70b32d8..7f5309a 100644 --- a/1_MongoDB/README.md +++ b/1_MongoDB/README.md @@ -1,45 +1,91 @@ -# Install MongoDB -MongoDB is an open-source, document-oriented database designed for ease of development and scaling. The MongoDB documentation site includes a [tutorial on how to install MongoDB on RHEL-based system](http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/). +# Usage +Assumption: You have a virtualbox with centOs7 and ChefDk 2.4.17 +1) Copy the cookook to your virtualBox running CentOs 7 and ChefDk kit ver 2.4.17. +2) Login as super user on terminal. +3) Change working directory to /cookbooks/mongodb. +4) Run mongo install cookbook : + sudo chef-client --local-mode recipes/default.rb -## Goal +# Test + From terminal, login mongo shell: -Use Chef to successfully install MongoDB on a RHEL-based target system. + > mongo + + Result: + You are now logged in: + root@osboxes mongodb]# mongo + MongoDB shell version v3.6.2 + connecting to: mongodb://127.0.0.1:27017 + MongoDB server version: 3.6.2 + -etc.(truncated)---- -## Success Criteria -You should be prepared and able to demonstrate the following: +# Setup & Environment +Note : This setup was done one time to set the environment of my virtualBox using centOS7 +and ChefDk kit ver 2.4.17 -* Your Chef cookbook successfully executes on your target node without errors -* Your Chef cookbook is portable and can be run by Chef to validate your work. Please include any instructions or assumptions needed to successfully execute your cookbook. -* You can login to MongoDB by typing `mongo` on the target system -* You can run `chef-client` multiple times without failures -* Your GitHub.com source code repository shows the history of your work +1) Downloaded and install VirtualBox running CentOs 7 - Linux 64 bit +2) Install chef in the virtual machine using the command: +> $ sudo rpm -Uvh https://packages.chef.io/files/stable/chefdk/2.4.17/el/7/chefdk-2.4.17-1.el7.x86_64.rpm -You should be able to explain the following: +Result: +Retrieving https://packages.chef.io/files/stable/chefdk/2.4.17/el/7/chefdk-2.4.17-1.el7.x86_64.rpm +----etc [Truncated] +Thank you for installing Chef Development Kit! -* Steps taken to achieve the end result -* Build and test process of Chef code -* Tools and resources used in the process +3) Now set the Ruby version to be used as the Chefdk version: + Ruby Version set to chef sdk ver: + echo 'export PATH="/opt/chefdk/embedded/bin:$PATH"' >> ~/.configuration_file && source ~/.configuration_file + echo 'export PATH="/opt/chefdk/embedded/bin:$PATH"' >> ~/.bash_profile && source ~/.bash_profile ->Note: You are NOT required to use Chef Server for this exercise, but you may if that is your preference. +# MongoDB-install Chef Recipe creation instructions: -## Instructions +1) Create a directory called mongo-chef. We will use this directory to store the recipe to install mongo Db +We have already downloaded chef Sdk in the previous step +2) Rebooted my Virtual box and logged in as root +3) create a dir for chef repository, here we will generate and store all our cookbooks. +4) [root@osboxes /]# mkdir mongo-chef +5) mkdir cookbook + RESULT: + [root@osboxes mongo-chef]# ls + cookbooks -* Translate the MongoDB installation instructions from `install.rb` into Chef code that completes the installation -* Use the Chef [Resources Reference](https://docs.chef.io/resources.html) to find the most appropriate Chef resources to use for each task -* Once you feel you have met the success criteria outlined above, send a link to your GitHub.com repo to the person coordinating these workshops -* Provide instructions for us to run your cookbook so that we can test your work. +6) Next, generate a cookbook for all mongoldb installation instructions: + [root@osboxes mongo-chef]# chef generate cookbook cookbooks/mongodb + RESULT: + Generating cookbook mongodb + - [Truncated] .. + Your cookbook is ready. Type `cd cookbooks/mongodb` to enter it. -There are a couple of ways that you can write, test and run your cookbook. +7) Check the directory structure. I have already installed the tree package to view directories as tree +[root@osboxes mongodb]# tree +. + ├── Berksfile + ├── chefignore + ├── LICENSE + ├── metadata.rb + ├── README.md + ├── recipes + │   └── default.rb + ├── spec + │   ├── spec_helper.rb + │   └── unit + │ └── recipes + │   └── default_spec.rb + └── test + └── smoke + └── default + └── default_test.rb +7 directories, 9 files + +8) Create a recipe file where I will enter the resources and actions to perform on each resource to install mongoldb. + +9) Now run the Cookbook: +[root@osboxes recipes]# chef-client --local-mode default.rb + RESULT - 5X unsuccessful runs with errors - please see unsucessful_runs.txt, with possible issues and solutions. + + 6 th time sucess! -* Write and test your cookbook locally using Test Kitchen via Vagrant + Virtual Box, or the cloud platform of your choice. - * Steps for this option are outlined [here](https://learn.chef.io/tutorials/local-development/) -* Develop directly on your RHEL-based virtual machine - * Write your cookbook in vim, nano or emacs, and run `chef-client` in `--local-mode` - * The ChefDK or Chef Client must be installed on the VM first -## Suggested Resources -* Use the [Chef Documentation](http://docs.chef.io) to identify and use resources that will help you model the desired state of your infrastructure. -* [MongoDB Installation Instructions](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/) diff --git a/1_MongoDB/cookbooks/mongodb/Berksfile b/1_MongoDB/cookbooks/mongodb/Berksfile new file mode 100644 index 0000000..0656a99 --- /dev/null +++ b/1_MongoDB/cookbooks/mongodb/Berksfile @@ -0,0 +1,4 @@ +# frozen_string_literal: true +source 'https://supermarket.chef.io' + +metadata diff --git a/1_MongoDB/cookbooks/mongodb/LICENSE b/1_MongoDB/cookbooks/mongodb/LICENSE new file mode 100644 index 0000000..a27e740 --- /dev/null +++ b/1_MongoDB/cookbooks/mongodb/LICENSE @@ -0,0 +1,3 @@ +Copyright 2018 The Authors + +All rights reserved, do not redistribute. diff --git a/1_MongoDB/cookbooks/mongodb/README.md b/1_MongoDB/cookbooks/mongodb/README.md new file mode 100644 index 0000000..32dc913 --- /dev/null +++ b/1_MongoDB/cookbooks/mongodb/README.md @@ -0,0 +1,4 @@ +# mongodb + +TODO: Enter the cookbook description here. + diff --git a/1_MongoDB/cookbooks/mongodb/chefignore b/1_MongoDB/cookbooks/mongodb/chefignore new file mode 100644 index 0000000..38e7379 --- /dev/null +++ b/1_MongoDB/cookbooks/mongodb/chefignore @@ -0,0 +1,107 @@ +# Put files/directories that should be ignored in this file when uploading +# to a chef-server or supermarket. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +examples/* +Guardfile +Procfile +.kitchen* +.rubocop.yml +spec/* +Rakefile +.travis.yml +.foodcritic +.codeclimate.yml + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Policyfile # +############## +Policyfile.rb +Policyfile.lock.json + +# Cookbooks # +############# +CONTRIBUTING* +CHANGELOG* +TESTING* +MAINTAINERS.toml + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile diff --git a/1_MongoDB/cookbooks/mongodb/metadata.rb b/1_MongoDB/cookbooks/mongodb/metadata.rb new file mode 100644 index 0000000..588abb2 --- /dev/null +++ b/1_MongoDB/cookbooks/mongodb/metadata.rb @@ -0,0 +1,20 @@ +name 'mongodb' +maintainer 'The Authors' +maintainer_email 'you@example.com' +license 'All Rights Reserved' +description 'Installs/Configures mongodb' +long_description 'Installs/Configures mongodb' +version '0.1.0' +chef_version '>= 12.1' if respond_to?(:chef_version) + +# The `issues_url` points to the location where issues for this cookbook are +# tracked. A `View Issues` link will be displayed on this cookbook's page when +# uploaded to a Supermarket. +# +# issues_url 'https://github.com//mongodb/issues' + +# The `source_url` points to the development repository for this cookbook. A +# `View Source` link will be displayed on this cookbook's page when uploaded to +# a Supermarket. +# +# source_url 'https://github.com//mongodb' diff --git a/1_MongoDB/cookbooks/mongodb/recipes/default.rb b/1_MongoDB/cookbooks/mongodb/recipes/default.rb new file mode 100644 index 0000000..e81e6a8 --- /dev/null +++ b/1_MongoDB/cookbooks/mongodb/recipes/default.rb @@ -0,0 +1,43 @@ +# +# Cookbook:: mongodb +# Recipe:: default +# +# Copyright:: 2018, The Authors, All Rights Reserved. + +# add yum clean all. +# yum update + + +yum_repository 'mongodb' do + description "MongoDB Repository" + baseurl "http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/" + gpgcheck false + enabled true + action :create +end + +package 'mongodb-org' do + :install +end + + +#service mongod start + +service 'mongod' do + #supports : restart => true + action [:enable, :start] +end + + +execute 'chkconfig' do + #command 'mongo --host 127.0.0.1:27017' + command 'sudo mongo' + action :run + live_stream true +ignore_failure true +end + + + + + diff --git a/1_MongoDB/cookbooks/mongodb/spec/spec_helper.rb b/1_MongoDB/cookbooks/mongodb/spec/spec_helper.rb new file mode 100644 index 0000000..052d78a --- /dev/null +++ b/1_MongoDB/cookbooks/mongodb/spec/spec_helper.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true +require 'chefspec' +require 'chefspec/berkshelf' diff --git a/1_MongoDB/cookbooks/mongodb/spec/unit/recipes/default_spec.rb b/1_MongoDB/cookbooks/mongodb/spec/unit/recipes/default_spec.rb new file mode 100644 index 0000000..76eab9b --- /dev/null +++ b/1_MongoDB/cookbooks/mongodb/spec/unit/recipes/default_spec.rb @@ -0,0 +1,35 @@ +# +# Cookbook:: mongodb +# Spec:: default +# +# Copyright:: 2018, The Authors, All Rights Reserved. + +require 'spec_helper' + +describe 'mongodb::default' do + context 'When all attributes are default, on Ubuntu 16.04' do + let(:chef_run) do + # for a complete list of available platforms and versions see: + # https://github.com/customink/fauxhai/blob/master/PLATFORMS.md + runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04') + runner.converge(described_recipe) + end + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + end + + context 'When all attributes are default, on CentOS 7.4.1708' do + let(:chef_run) do + # for a complete list of available platforms and versions see: + # https://github.com/customink/fauxhai/blob/master/PLATFORMS.md + runner = ChefSpec::ServerRunner.new(platform: 'centos', version: '7.4.1708') + runner.converge(described_recipe) + end + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + end +end diff --git a/1_MongoDB/cookbooks/mongodb/test/smoke/default/default_test.rb b/1_MongoDB/cookbooks/mongodb/test/smoke/default/default_test.rb new file mode 100644 index 0000000..a70e26b --- /dev/null +++ b/1_MongoDB/cookbooks/mongodb/test/smoke/default/default_test.rb @@ -0,0 +1,18 @@ +# # encoding: utf-8 + +# Inspec test for recipe mongodb::default + +# The Inspec reference, with examples and extensive documentation, can be +# found at http://inspec.io/docs/reference/resources/ + +unless os.windows? + # This is an example test, replace with your own test. + describe user('root'), :skip do + it { should exist } + end +end + +# This is an example test, replace it with your own test. +describe port(80), :skip do + it { should_not be_listening } +end