chef execute resource does not working on Rhel 8 - resources

I am using execute resource in cookbook recipe. the recipe is working normaly while recipe calling on cli. the recipe does not working schedule with cron. i send error log below;
* execute[DNS Recording with Centrify] action run
================================================================================
Error executing action `run` on resource 'execute[DNS Recording with Centrify]'
================================================================================
Errno::ENOENT
-------------
No such file or directory - addns
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/rhel8/recipes/centrify.rb
48: execute 'DNS Recording with Centrify' do
49: command 'addns -U -m'
50: user "root"
51: ignore_failure false
52: end
53: end
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/rhel8/recipes/centrify.rb:48:in `from_file'
execute("DNS Recording with Centrify") do
action [:run]
default_guard_interpreter :execute
command "addns -U -m"
declared_type :execute
cookbook_name "rhel8"
recipe_name "centrify"
domain nil
user "root"
end
i found the reason. the reason appear baceuse of different PATH. cookbook uses different PATH in the cli and in different cron. Mycommand binary in the cli PATH. i can not use static PATH because of cli PATH changes according to OS, verison and distribution.
how can set cli PATH in the cookbook according to all linux?
Regards

From the question it appears you want to have the respective PATH environment variable available for the execute resource.
You can try two options:
Set the environment variable PATH while executing command:
execute 'DNS Recording with Centrify' do
command 'addns -U -m'
user 'root'
environment(
{ 'PATH' => ENV['PATH'] }
)
end
Or use default_env property of resource to see if makes the PATH available:
execute 'DNS Recording with Centrify' do
command 'addns -U -m'
user 'root'
default_env true
end

Related

Oracle Silent Install Failing in Chef

I'm trying to install Oracle on a RHEL VM in Chef. When I directly log into the VM as the install user ("oracle1") and run the silent install command:
./runInstaller -ignorePrereq -waitforcompletion -silent -responseFile /u01/app/oracle/product/19.0.0/dbhome_1/install/response/db_install.rsp
the installation is successful.
I want to automate this installation by adding it to my existing Chef recipes, which I am currently attempting using the following block:
execute 'install oracle' do
command './runInstaller -ignorePrereq -waitforcompletion -silent -responseFile /u01/app/oracle/product/19.0.0/dbhome_1/install/response/db_install.rsp'
cwd '/u01/app/oracle/product/19.0.0/dbhome_1'
user 'oracle1'
group 'oinstall'
#not_if { ::File.exist?("/u01/app/oracle/product/completed.txt") }
end
However, this block fails and results in the following error:
[FATAL] [INS-32042] The Installer has detected that the user (oracle1) is not a member of the central inventory group: oinstall
ACTION: Make sure that the user (oracle1) is member of the central inventory group (oinstall)
But, previously in the recipe, I run the block:
execute 'luseradd' do
command 'sudo luseradd -g oinstall -d /home/oracle1 -s /bin/bash oracle1'
not_if { Dir.exist?("/home/oracle1") }
end
which (as far as I am aware) contradicts the error message I get. Also, when I check the groups that oracle1 is part of, oinstall is listed as one of them.
Any help/pointers would be appreciated!
You can modify the execute block like this:
execute 'install oracle' do
command 'sudo -Eu oracle1 ./runInstaller -ignorePrereq -waitforcompletion -silent -responseFile /u01/app/oracle/product/19.0.0/dbhome_1/install/response/db_install.rsp'
cwd '/u01/app/oracle/product/19.0.0/dbhome_1'
#not_if { ::File.exist?("/u01/app/oracle/product/completed.txt") }
end
Additionally you may need to modify your user oracle1 so it can execute commands without passing root password.

Not able to set environment variable for sudo -u "user"

I am at my wits end trying to figure this out
When I execute the following command:
sudo -u icinga '/usr/lib//nagios/plugins/check_db2_health' '--database' 'mydatabase' '--environment' 'DB2DIR=/opt/IBM/db2/V11.1.4fp5a' '--environment' 'DB2INSTANCE=mydatabase' '--environment' 'INSTHOME=/srv/db2/home/mydatabase' '--report' 'short' '--username' 'icinga' '--mode' 'connection-time' '--warning' '50'
The output as follow
[DBinstance : mydatabase] Status : CRITICAL - cannot connect to mydatabase. install_driver(DB2) failed: Can't load '/usr/lib/nagios/plugins/PerlLib/lib/perl5/site_perl/5.18.2/x86_64-linux-thread-multi/auto/DBD/DB2/DB2.so' for module DBD::DB2: libdb2.so.1: cannot open shared object file: No such file or directory at /usr/lib/perl5/5.18.2/x86_64-linux-thread-multi/DynaLoader.pm line 190.
at (eval 10) line 3.
Compilation failed in require at (eval 10) line 3.
Perhaps a required shared library or dll isn't installed where expected
at /usr/lib//nagios/plugins/check_db2_health line 2627.
But when I login to the user icinga using su - icinga
And run
'/usr/lib//nagios/plugins/check_db2_health' '--database' 'mydatabase' '--environment' 'DB2DIR=/opt/IBM/db2/V11.1.4fp5a' '--environment' 'DB2INSTANCE=mydatabase' '--environment' 'INSTHOME=/srv/db2/home/mydatabase' '--report' 'short' '--username' 'icinga' '--mode' 'connection-time' '--warning' '50'
It works fine.
How do I setup environment variables when sudo - u icinga command is fired ?
I am on a SUSE linux
I am kind of trying to setup a global environment variable just like the environment variable in icinga which can work across all commands executed on the server without have to use sudo -E etc because I cannot change the way icinga calls the plugin
you need to run the db2profile when you sudo
sudo -u icinga sqllib/db2profile; '/usr/lib//nagios/plugins/check_db2_health' ...

Puppet task run throwing invalid json error

My Puppet sever is PE 2017.3.1
My Agent node is on 5.5 version
I am facing an error while executing the command
/opt/puppetlabs/puppet/bin/puppet-task run sample --nodes puppet-agent
My Sample file is a bash file which contains : -
#!/usr/bin/env bash
hostnamectl
I was able to list my task using cli
The above puppet-task command throws an error on command line: -
1. Starting Job
2. Invalid Json
Puppet access login token expired. So after recreating it, I was able to perform the task.

Shell scripts using Cron can't execute shell commands

I'm trying to restart my server with cron. I've found this link:
https://help.openshift.com/hc/en-us/articles/202187644-Shell-scripts-using-Cron-or-action-hooks-can-t-execute-shell-commands
But does not work. This is my script:
#!/bin/bash
source /usr/bin/rhcsh
ctl_all restart
And this the output:
/usr/bin/rhcsh: line 7: source: filename argument required
source: usage: source filename [arguments]
/usr/bin/rhcsh: line 32: build_path: command not found
/usr/bin/rhcsh: line 33: build_ld_library_path: No such file or directory
*********************************************************************
You are accessing a service that is for use only by authorized users.
If you do not have authorization, discontinue use at once.
Any use of the services is subject to the applicable terms of the
agreement which can be found at:
https://www.openshift.com/legal
*********************************************************************
Welcome to OpenShift shell
This shell will assist you in managing OpenShift applications.
!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
Shell access is quite powerful and it is possible for you to
accidentally damage your application. Proceed with care!
If worse comes to worst, destroy your application with "rhc app delete"
and recreate it
!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
Type "help" for more info.
Command "quota" not found for app xxxxx, please check the node hosting this app
WARNING: This ssh terminal was started without a tty.
It is highly recommended to login with: ssh -t
Restarting services
/usr/bin/rhcsh: line 123: gear: No such file or directory
Any ideas?
Many thanks.
Edit:
Here is rhcsh script (The script has 300 lines, so I've uploaded to a server):
http://www6.zippyshare.com/v/99209351/file.html
Try this:
#!/bin/bash
gear restart --all-cartridges # same as: ctl_all restart
ctl_all is a wrapper function for /usr/bin/gear script.

Capistrano check fails on DigitalOcean VPS

I'm trying to deploy a Node.js app to a VPS running on DigitalOcean and so far I'm getting well..very far. My understanding of *nix is very limited so please bear with me :)
I can ssh as root into my VPS (Ubuntu 13.04 x32) with my SSH keys without any problems. When I run "$cap deploy:setup" on my local machine I get this result:
* 2013-09-11 12:39:08 executing `deploy:setup'
* executing "mkdir -p /var/www/yable /var/www/yable/releases /var/www/yable/shared /var/www/yable/shared/system /var/www/yable/shared/log /var/www/yable/shared/pids"
servers: ["162.243.1.207"]
[162.243.1.207] executing command
** [out :: 162.243.1.207] env: sh: No such file or directory
command finished in 118ms
failed: "env PATH=/var/www/yable NODE_ENV=production sh -c 'mkdir -p /var/www/yable /var/www/yable/releases /var/www/yable/shared /var/www/yable/shared/system /var/www/yable/shared/log /var/www/yable/shared/pids'" on 162.243.1.207
When I run "$cap deploy:check" I get the following output:
* 2013-09-11 12:40:36 executing `deploy:check'
* executing "test -d /var/www/yable/releases"
servers: ["162.243.1.207"]
[162.243.1.207] executing command
command finished in 67ms
* executing "test -w /var/www/yable"
servers: ["162.243.1.207"]
[162.243.1.207] executing command
command finished in 76ms
* executing "test -w /var/www/yable/releases"
servers: ["162.243.1.207"]
[162.243.1.207] executing command
command finished in 69ms
* executing "which git"
servers: ["162.243.1.207"]
[162.243.1.207] executing command
command finished in 75ms
The following dependencies failed. Please check them and try again:
--> `/var/www/yable/releases' does not exist. Please run `cap deploy:setup'. (162.243.1.207)
--> You do not have permissions to write to `/var/www/yable'. (162.243.1.207)
--> You do not have permissions to write to `/var/www/yable/releases'. (162.243.1.207)
--> `git' could not be found in the path (162.243.1.207)
Here's my config/deploy.rb file:
set :application, "Yable.com"
set :scm, :git
set :repository, "git#github.com:Yable/yable-node-js.git"
set :user, "root"
set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true
set :use_sudo, false
set :branch, "master"
role :app, "162.243.1.207"
set :deploy_to, "/var/www/yable"
set :default_environment, {
'PATH' => "/var/www/yable",
'NODE_ENV' => 'production'
}
I'm dumbfounded as the directory mentioned (/var/www/yable/releases) does exist and that git has been installed. Any ideas?
Thanks,
Francis
I installed ruby 2.0.0 and Bundler and it seems to have solved my deployment issues.

Resources