Error while unzipping file on AIX system using CHEF - installation

I want to un zip / un tar a file on AIX system using CHEF.
Steps i have done :
1.I have uploaded a zip file Test.zip on AIX system using Winscp.
2.Edited the default.rb using below command:
execute "extract_Test_tar" do
command "tar -xvf Test.zip"
cwd "/var/chef/cookbooks"
end
3.While uploading my cookbook it is giving me following error:
Recipe: Infy_Patrol::default
* execute[extract_Test_tar] action run
================================================================================
Error executing action `run` on resource 'execute[extract_Test_tar]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of tar -xvf Test.zip ----
STDOUT:
STDERR: tar: tape blocksize error
---- End output of tar -xvf Test.zip ----
Ran tar -xvf Test.zip returned 1
Resource Declaration:
---------------------
# In /.chef/local-mode-cache/cache/cookbooks/Infy_Patrol/recipes/default.rb
10: execute "extract_Test_tar" do
11: command "tar -xvf Test.zip"
12: cwd "/var/chef/cookbooks"
13: end
Compiled Resource:
------------------
# Declared in /.chef/local-mode-cache/cache/cookbooks/Infy_Patrol/recipes/default.rb:10:in `from_file'
execute("extract_Test_tar") do
action [:run]
retries 0
retry_delay 2
default_guard_interpreter :execute
command "tar -xvf Test.zip"
backup 5
cwd "/var/chef/cookbooks"
returns 0
declared_type :execute
cookbook_name "Infy_Patrol"
recipe_name "default"
end
Running handlers:
[2016-01-29T06:27:47-06:00] ERROR: Running exception handlers
Running handlers complete
[2016-01-29T06:27:47-06:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 05 seconds
[2016-01-29T06:27:47-06:00] FATAL: Stacktrace dumped to /.chef/local-mode-cache/cache/chef-stacktrace.out
[2016-01-29T06:27:47-06:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-01-29T06:27:47-06:00] ERROR: execute[extract_Test_tar] (Infy_Patrol::default line 10) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'

REPHRASING MY QUESTION.
Below are the steps I followed :
1.Logged into my AIX machine.2.Logged into Winscp.
3.created a cookbook using : knife cookbook create Test
4.Using winscp i went to the path where my cookbook is saved:
/var/chef/cookbooks/Test 5.Opened recipes folder: and edited default.rb as given:
#
# Cookbook Name:: Infy_Patrol
# Recipe:: default
#
# Copyright 2016, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
tar_extract '/var/chef/cookbooks/Test.zip' do
action :extract_local
target_dir '/var/chef/cookbooks'
creates '/var/chef/cookbooks/new'
end
#Also tried the following piece of code
#execute "extract files" do
#command "tar xvf Test.tar.gz -C /var/chef/cookbooks"
#end
6.uploaded cookbook using :
chef-client -z -r Test::default
BUT IT IS GIVING ME AN ERROR :
Error executing action `run` on resource 'execute[extract_Test_tar]

Related

JMeter-Taurus Docker Image Error - "No personal config found, creating one at /.bzt-rc"

I am trying to run a performance test within a Drone pipeline using JMeter-Taurus. I am pulling the latest (stable) image for blazemeter-taurus. However, when running the test in a pipeline the following error is returned.
This is the contents of the Dockerfile:
FROM blazemeter/taurus
RUN apt-get update && \
python3 -m pip install s3cmd
COPY . /bzt/
COPY config/90-artifacts-dir.json /etc/bzt.d/
COPY config/90-no-console.json /etc/bzt.d/
COPY .bzt-rc /root/.bzt-rc
RUN chown -R 1000:1000 /bzt && \
sed -i -e '/^assistive_technologies=/s/^/#/' /etc/java-*-openjdk/accessibility.properties
USER 1000
VOLUME ["/bzt"]
WORKDIR /bzt
UPDATE:
The "USER 1000" part has been removed. And the following line was added:
RUN chmod +x /bzt
But this is the error message returned:
Traceback (most recent call last):
File "/usr/local/bin/bzt", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.9/dist-packages/bzt/cli.py", line 676, in main
executor = CLI(parsed_options)
File "/usr/local/lib/python3.9/dist-packages/bzt/cli.py", line 56, in __init__
self.setup_logging(options)
File "/usr/local/lib/python3.9/dist-packages/bzt/cli.py", line 111, in setup_logging
file_handler = logging.FileHandler(options.log, encoding="utf-8")
File "/usr/lib/python3.9/logging/__init__.py", line 1146, in __init__
StreamHandler.__init__(self, self._open())
File "/usr/lib/python3.9/logging/__init__.py", line 1175, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding,
PermissionError: [Errno 13] Permission denied: '/bzt/bzt.log'
######## TEST RUN STATUS : 1 #######
cat: /bzt/bzt_artifacts/bzt.log: No such file or directory
cat: /bzt/bzt_artifacts/error.jtl: No such file or directory
ls: cannot access '/bzt/bzt_artifacts/': No such file or directory
Taurus Docker image is root-oriented, here is the Dockerfile
I fail to see why Taurus is trying to create its config under /.bzt-rc, it may be some this "Drone pipeline" specifics, my expectation is that your test will fail because your user 1000 doesn't have write permissions to /tmp folder where Taurus stores its Artifacts

fail2ban "command not found" when executing banaction

One of the actions for fail2ban is configured to run a ruby script; however, fail2ban fails when trying to execute the ruby script with a "Command not found" error. I don't understand this error because I'm providing the full path to the ruby script and it has execution permissions:
Here's my fail2ban action:
[root:a17924e746f0:~]# cat /etc/fail2ban/action.d/404.conf
# Fail2Ban action configuration file for Subzero/Core
[Definition]
actionstart =
actionstop =
actioncheck =
actionban = /root/ban_modify.rb ban <ip>
actionunban = /root/ban_modify.rb unban <ip>
Here are the contents to the /root/ban_modify.rb script:
#!/usr/bin/env ruby
command = ARGV[0]
ip_address = ARGV[1]
blacklist = File.open("/root/blacklist.txt").read.split("\n")
if command == "unban"
if blacklist.include? "#{ip_address} deny"
blacklist.delete "#{ip_address} deny"
end
elsif command == "ban"
blacklist << "#{ip_address} deny"
end
File.open("/root/blacklist.txt", "w") {|f| f.write(blacklist.join("\n"))}
Very simple. This blacklist.txt file is used by Apache to permanently ban individuals from the web server when a fail2ban condition is met.
However, when I issue the following command: sudo /usr/bin/fail2ban-client set 404 unbanip <my ip>
I get the following error:
2019-08-19 20:56:43,508 fail2ban.utils [16176]: Level 39 7ff7395873f0 -- exec: ban_modify.rb ban <myip>
2019-08-19 20:56:43,509 fail2ban.utils [16176]: ERROR 7ff7395873f0 -- stderr: '/bin/sh: 1: ban_modify.rb: not found'
2019-08-19 20:56:43,509 fail2ban.utils [16176]: ERROR 7ff7395873f0 -- returned 127
2019-08-19 20:56:43,509 fail2ban.utils [16176]: INFO HINT on 127: "Command not found". Make sure that all commands in 'ban_modify.rb ban <myip>' are in the PATH of fail2ban-server process (grep -a PATH= /proc/`pidof -x fail2ban-server`/environ). You may want to start "fail2ban-server -f" separately, initiate it with "fail2ban-client reload" in another shell session and observe if additional informative error messages appear in the terminals.
2019-08-19 20:56:43,509 fail2ban.actions [16176]: ERROR Failed to execute ban jail '404' action '404' info 'ActionInfo({'ip': '<myip>', 'family': 'inet4', 'ip-rev': '<myip>.', 'ip-host': '<myip>', 'fid': '<myip>', 'failures': 1, 'time': 1566266203.3465006, 'matches': '', 'restored': 0, 'F-*': {'matches': [], 'failures': 1}, 'ipmatches': '', 'ipjailmatches': '', 'ipfailures': 1, 'ipjailfailures': 1})': Error banning <myip>
I'm not sure why this error is happening if the actionban is pointing to the full path of a ruby script.
I even tried changing the contents of /root/ban_modify.rb to just simply puts "Hello World". Tried changing the banaction to iptables-allports and that still failed. It seems like banaction just simply doesn't work.
You can enable fail2ban debug mode & check fail2ban log for more details.
# change fail2ban log level
sudo nano /etc/fail2ban/fail2ban.conf
loglevel = DEBUG
# restart fail2ban
sudo systemctl restart fail2ban
# check logs
tail -f /var/log/fail2ban.log
You can restart the fail2ban and check it again:
sudo systemctl restart fail2ban

Chef:Install windows_feature with guard clause not_if

I'm using Chef 12.4 and using chef-client in local mode. I'm trying to install windows features and detect their current status before I do the installation, or removal. The reason for using the not if, is because when using DISM it takes for ever to check the current state.
Currently I have a server that takes 45 minutes to build and then 20 minutes to run chef even when there is nothing to do.
I used the following Powershell script 'service-check.ps1' to output the status of the package, this is put in place by the recipe itself:
$content = Get-Content .\features.txt
$feature = $args[0]
function grep($f) {
foreach($_ in $content){
$data = $_.split("|")
%{if($($data[0]) -match $f) {return "$($data[1])"}}
}
}
grep $feature
The recipe I'm using writes the 'features.txt' file to the location where Chef is being run, by querying dism for the current features and their status. The recipe file is as follows:
#Check the features and their current state
powershell_script 'installed_features' do
code <<-EOH
dism /online /get-features /format:table > c://chef//features.txt
EOH
end
cookbook_file 'C:\Scripts\service-check.ps1' do
source 'service-check.ps1'
end
windows_feature 'TelnetClient' do
action :remove
only_if {
status = powershell_out("Powershell -f C:\\scripts\\service-check.ps1 TelnetClient").stdout.chop
Disabled != status
}
end
I have tried many different formats in the only_if {} segment, however none of them have worked. I used the example that is here:
http://pdalinis.blogspot.co.uk/2013/09/chef-using-powershell-as-conditional.html
The output I get is:
* windows_feature[TelnetClient] action remove
================================================================================
Error executing action `remove` on resource 'windows_feature[TelnetClient]'
================================================================================
NameError
---------
uninitialized constant Chef::Recipe::Disabled
Resource Declaration:
---------------------
# In C:/chef/local-mode-cache/cache/cookbooks/tester/recipes/default.rb
12: windows_feature 'TelnetClient' do
13: action :remove
14: only_if {
15: status = powershell_out("Powershell -f C:\\scripts\\service-check.ps1 TelnetClient").stdout.chop
16: Disabled != status
17: }
18: end
Compiled Resource:
------------------
# Declared in C:/chef/local-mode-cache/cache/cookbooks/tester/recipes/default.rb:12:in `from_file'
windows_feature("TelnetClient") do
provider LWRP provider windows_feature_dism from cookbook windows
action [:remove]
retries 0
retry_delay 2
default_guard_interpreter :default
declared_type :windows_feature
cookbook_name "tester"
recipe_name "default"
only_if { #code block }
end
I'm a novice at Chef, Ruby and Powershell. I'm assuming that the only_if or not_if are expecting a true or false result, however this seems to be appending the written status that I've added the check against (in this script, disabled).
I have checked the powershell script, it does indeed output Enabed / Disabled depending on the status.
My questions are:
Is it possible to use windows_feature and powershell_out in this way, according to the example it's using powershell_script, but I'd rather use the windows_feature specification to install features.
If it is possible, what am I doing wrong? I have a feeling it might be the output of the script as it seems to insert a space:
" Enabled"
" Disabled"
If it isn't possible, is there another way to do it?
I'd be very grateful for any assistance.
Thank you.
is it possible you just need to quote "Disabled"? Otherwise Ruby is trying to figure out what it is, but doesn't know about any variable or class with that name.

How to use special characters in Chef?

I am writing Chef recipes using chef-solo, where I need to run commands which include + but Chef returns an error if I use the + character.
bash "testing" do
code <<-EOH
/bin/grep '^+:' /etc/shadow >>/var/info
EOH
end
Method 1: put code in any script.sh file and use it as:
execute " script running " do
command "sh /path/script.sh"
end
but I don't want to use it. Is there any other way to use special characters?
Note: I tried using back-slash ("\").
update : got below error when i use code
bash "testing" do
code "/bin/grep '^+:' /etc/shadow >>/var/info"
end
Error:
chef-solo -c solo.rb -j web.json
Starting Chef Client, version 11.8.2
Compiling Cookbooks...
Converging 1 resources
Recipe: test::test
* bash[testing] action run
================================================================================
Error executing action `run` on resource 'bash[testing]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of "bash" "/tmp/chef-script20150822-12224-kbivpd" ----
STDOUT:
STDERR:
---- End output of "bash" "/tmp/chef-script20150822-12224-kbivpd" ----
Ran "bash" "/tmp/chef-script20150822-12224-kbivpd" returned 1
Resource Declaration:
---------------------
# In /home/new/cookbooks/test/recipes/test.rb
1: bash "testing" do
2: code "/bin/grep '^+:' /etc/shadow >>/var/info"
3: end
Compiled Resource:
------------------
# Declared in /home/new/cookbooks/test/recipes/test.rb:1:in `from_file'
bash("testing") do
action "run"
retries 0
retry_delay 2
command "\"bash\" \"/tmp/chef-script20150822-12224-kbivpd\""
backup 5
returns 0
code "/bin/grep '^+:' /etc/shadow >>/var/info"
interpreter "bash"
cookbook_name :test
recipe_name "test"
end
[2015-08-22T19:49:52+05:30] ERROR: Running exception handlers
[2015-08-22T19:49:52+05:30] ERROR: Exception handlers complete
[2015-08-22T19:49:52+05:30] FATAL: Stacktrace dumped to /home/chef-solo/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2015-08-22T19:49:52+05:30] ERROR: bash[testing] (test::test line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash" "/tmp/chef-script20150822-12224-kbivpd" ----
STDOUT:
STDERR:
---- End output of "bash" "/tmp/chef-script20150822-12224-kbivpd" ----
Ran "bash" "/tmp/chef-script20150822-12224-kbivpd" returned 1
[2015-08-22T19:49:52+05:30] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
This has nothing to do with the + in the command !
There's nothing wrong, chef works as expected:
# grep '^+' /etc/shadow; echo $?
1
This command returns a status code of 1 as nothing is found (quote of man grep emphasis is mine):
EXIT STATUS
The exit status is 0 if selected lines are found, and 1 if not found. If an error occurred the exit status is 2. (Note: POSIX
error handling
code should check for '2' or greater.)
And chef tell's you exactly this:
Expected process to exit with [0], but received '1'
Reading the bash resource documentation we see there's a returns attribute with this description:
returns Ruby Types: Integer, Array
The return value for a command. This may be an array of accepted
values. An exception is raised when the return value(s) do not match.
Default value: 0.
So if you want to accept this command return 0 or 1:
bash "testing" do
code "/bin/grep '^+:' /etc/shadow >>/var/info"
return [0,1]
end
So this may not solve your problem as you didn't describe what you're trying to achieve, we're on a XY problem here
Chef recipes are pure ruby, so you can write something like this without any problems:
bash "testing" do
code "/bin/grep '^+:' /etc/shadow >>/var/info"
end
If you need to use double quotes inside your command, you can escape it with back slash "\".
i solved my problem using
`/bin/grep '^+:' /etc/passwd >> /var/output`
this is ruby method to execute system command using backticks in which global variable $? is set through the backticks automatically

cloud-init per-boot script on ubuntu ec2-instance

I am trying to start a script with cloud-init on a ubuntu 11.10 ec2 instance.
I put the script script.sh in the folder /var/lib/cloud/scripts/per-boot.
Content of script.sh is simple:
#/!/bin/sh
echo "test"
After a reboot, I get the following error:
run-parts: failed to exec /var/lib/cloud/scripts/per-boot/script.sh: Exec format error
run-parts: /var/lib/cloud/scripts/per-boot/script.sh exited with return code 1
2012-04-14 19:10:52,642 - cc_scripts_per_boot.py[WARNING]: failed to run-parts in /var/lib/cloud/scripts/per-boot
2012-04-14 19:10:52,648 - __init__.py[WARNING]: Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/cloudinit/CloudConfig/__init__.py", line 108, in run_cc_modules
cc.handle(name, run_args, freq=freq)
File "/usr/lib/python2.7/dist-packages/cloudinit/CloudConfig/__init__.py", line 72, in handle
[ name, self.cfg, self.cloud, cloudinit.log, args ])
File "/usr/lib/python2.7/dist-packages/cloudinit/__init__.py", line 309, in sem_and_run
func(*args)
File "/usr/lib/python2.7/dist-packages/cloudinit/CloudConfig/cc_scripts_per_boot.py", line 27, in handle
util.runparts(runparts_path)
File "/usr/lib/python2.7/dist-packages/cloudinit/util.py", line 140, in runparts
raise subprocess.CalledProcessError(sp.returncode,cmd)
CalledProcessError: Command '['run-parts', '--regex', '.*', '/var/lib/cloud/scripts/per-boot']' returned non-zero exit status 1
2012-04-14 19:10:52,648 - __init__.py[ERROR]: config handling of scripts-per-boot, None, [] failed
cloud-init boot finished at Sat, 14 Apr 2012 19:10:52 +0000. Up 3.70 seconds
2012-04-14 19:10:52,672 - cloud-init-cfg[ERROR]: errors running cloud_config [final]: ['scripts-per-boot']
errors running cloud_config [final]: ['scripts-per-boot']
Any ideas how to fix it?
I believe your problem is related to the fact that #/!/bin/sh is not a valid input type. Need to remove the / after the #.
#!/bin/sh
echo "test"
Let me know if you still see the problems after this.

Resources