Running knife commands from Capistrano task - capistrano

I'm attempting to configure the knife commandline tool via a capistrano task, and running into an issue when it hits the following line
system "knife configure --yes --defaults -s ... -c ... -u ... -r ..."
it says this
Could not find net-ssh-2.6.5 in any of the sources
Run `bundle install` to install missing gems.
I do have this gem installed and I believe it comes with chef. I assume this has something to do with the environment that Capistrano runs in.

Uninstall Chef:
gem uninstall chef
And re-install it:
gem install chef

Related

Running sbt in a Docker Container

I am trying to use Github actions for my scala project and created a Docker workflow for it. Basically, I am trying to install sbt into my container and run the project.
Dockerfile looks like this:
FROM centos:centos8
ENV SCALA_VERSION 2.13.1
ENV SBT_VERSION 1.5.2
RUN yum install -y epel-release
RUN yum update -y && yum install -y wget
# INSTALL JAVA
RUN yum install -y java-11-openjdk
# INSTALL SBT
RUN wget http://dl.bintray.com/sbt/rpm/sbt-${SBT_VERSION}.rpm
RUN yum install -y sbt-${SBT_VERSION}.rpm
RUN wget -O /usr/local/bin/sbt-launch.jar http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/$SBT_VERSION/sbt-launch.jar
WORKDIR /root
EXPOSE 8080
RUN sbt compile
CMD sbt run
But when I push anything, I get the following error:
The command '/bin/sh -c wget http://dl.bintray.com/sbt/rpm/sbt-${SBT_VERSION}.rpm' returned a non-zero code: 8
When I check the link manually (by setting the sbt version), I see indeed bintray responds with 403 forbidden error but status.bintray.com tells all systems are operational.
Am I doing something wrong or is something wrong with bintray?
Forbidden doesnt mean non operational.
I think that url is incorrect as its not hosted on bintray rather jfrog, please see section on Centos which states
remove old Bintray repo file
https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Linux.html

How to build and install wal2json without also installing the package postgresql-server-dev on Debian 9?

I'm trying to stream data automatically from PostgreSQL 10 to Kafka using debezium together with the logical decoding plugin, wal2json.
I followed all the instructions on how to build and install the plugin from this link by running these command lines:
$ git clone https://github.com/eulerto/wal2json.git
$ cd wal2json
$ PATH=/usr/lib/postgresql/10/bin:$PATH
$ USE_PGXS=1 make
$ USE_PGXS=1 sudo make install
Yet, the steps for installation include this command line: USE_PGXS=1 make and it requires the installation of this package
sudo apt-get install postgresql-server-dev-10
else, I get the following error
Makefile:10: /usr/lib/postgresql/11/lib/pgxs/src/makefiles/pgxs.mk: No such file or directory
make: *** No rule to make target '/usr/lib/postgresql/11/lib/pgxs/src/makefiles/pgxs.mk'. Stop.
In fact, I am not allowed to install the package postgresql-server-dev-10 for personal reasons.
Thus, is there any way to install wal2json without installing that package or without using the command make?
Thank you.

pg gem install fails, cannot find libpq-fe.h header

Whenever I run bundle install on my VPS (CentOS Linux release 7.0.1406 (Core)) I get an error when installing the pg gem.
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
I can install pg standalone with: gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config and the issue is resolved.
So I added a capistrano taskto create a ./bundle/config for the deploy with the build.pg key set with the path to pg_config on my VPS. In the Capistrano config/deploy.rb this is invoked before bundler:install.
desc "Create bundle config"
task :prepare_bundle_config do
on roles(:app) do
within release_path do
execute :bundle, 'config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config --local'
end
end
end
I have the necessary packages installed:
postgresql94-server.x86_64
postgresql94-devel.x86_64
postgresql94-libs.x86_64
libpqxx.x86_64
libpqxx-devel.x86_64
Here are the capistrano* gems I have installed
bundle list | grep capistrano
* capistrano (3.3.5)
* capistrano-bundler (1.1.4)
* capistrano-rails (1.1.2)
* capistrano-rbenv (2.0.3)
* capistrano-stats (1.1.1)
What am I missing here to successfully install pg with bundler? Please leave a comment if you need any additional information and I will update this post.
The postgres binaries are not in the path. Symlink them in to a directory in your path and you should be good: ln -s /usr/pgsql-9.4/bin/p* /usr/local/bin.
Did you build postgres or install it from yum?
Just posting the solution for PostgreSQL 11. If someone lands here.
sudo yum install epel-release
sudo yum install postgresql11-llvmjit
sudo yum install postgresql11-devel postgresql11-libs
Then run
gem install pg -v '1.2.3' -- --with-pg-config=/usr/pgsql-11/bin/pg_config
Thats it
I find that if I compile pgsql with source code, and PATH ENV not configed with pgsql/bin, this happends. You can have a try with this.
Alternatively, if you're using a Mac
brew link postgresql
Or in my case
brew link postgresql#12

Bundle with capistrano installed by chef

I'm configuring a vagrant box using chef and then deploying my app using capistrano.
my chef recipe to install bundler is the following:
include_recipe "rbenv"
include_recipe "rbenv::ruby_build"
rbenv_ruby node[:rbenv][:ruby] do
global true
end
rbenv_gem "bundler" do
ruby_version node[:rbenv][:ruby]
end
using the Riot rbenv cookbook
When I try using the bundle with capistrano I figured that the executed bundle is one that was preinstalled on the box, rather than the one installed by chef.
Here's the problem:
$ which bundle
/opt/rbenv/shims/bundle
$ sudo which bundle
/usr/bin/bundle
$ sudo su -
root# which bundle
/opt/rbenv/shims/bundle
Basically it appears that Capistrano runs the commands using the second form, were it uses the /usr/bin/bundle.
I've tried running:
$ sudo bundle
/usr/lib/ruby/vendor_ruby/bundler/rubygems_ext.rb:8:in `require': no such file to load -- rubygems (LoadError)
from /usr/lib/ruby/vendor_ruby/bundler/rubygems_ext.rb:8
from /usr/lib/ruby/vendor_ruby/bundler.rb:11:in `require'
from /usr/lib/ruby/vendor_ruby/bundler.rb:11
from /usr/bin/bundle:4:in `require'
from /usr/bin/bundle:4
and I obtain exactly the same exception I see in Capistrano.
If I manually uninstall bundler then here's what I obtain:
$ bundle
Bundler::GemfileNotFound
$ sudo bundle
sudo: bundle: command not found
$ sudo su -
root# bundle
Bundler::GemfileNotFound
UPDATE
I've figured that the whole ruby version is not available for sudoers:
$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
$ sudo ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
even more troubles.
Can you help me ?
thanks.
The problem is not that the rbenv-managed Ruby is not available to sudoers. The problem is that the system Ruby is used by default, unless overridden by something else -- usually .bashrc or a /etc/profile.d/* or such.
Since capistrano doesn't source any of these files, it uses the system Ruby.
You should tell cap to use the rbenv bin paths before the system ones by adding:
set :default_environment, {
'PATH' => "/opt/rbenv/shims:/opt/rbenv/bin:$PATH"
}
to your deploy.rb file.
Update
In Capistrano v3, the :default_environment has been renamed to :default_env.
Apparently tweaking with the default_env is a possibility, but not the preferred way.
as:
set :default_environment, {
'PATH' => "/opt/rbenv/shims:/opt/rbenv/bin:$PATH"
}
is not maintained by capistrano and probably even dangerous.
The preferred way is to look into the program one wants to run for a way to fix this.
In particular my problem: the RVM needs to be initialized upon shell startup, and any RVM installation tool will include your .bashrc with the call to the proper init script at the end of the file. Also at the beginning of .bashrc there's a command that exits the script when it's called on a non interactive shell.
Accidentally Capistrano runs the scripts on a non interactive shell, so when it calls RVM commands they are not initialized, in the non interactive shell.
The solution in my case was to edit the .bashrc file in chef so to call the RVM init script before exiting.

Setting up Mesos on CentOS

I tried to install the latest release tarball of Mesos on CentOS 6.4 with no luck. It ended up in all sorts of failures in trying to find jvm & jni bindings. Is there any instructions on how to install Mesos on RHEL or CentOS ?
I couldn't find any instructions around so I thought I would troubleshoot all through my way and thought of documenting it here so it can save your time.
First things first, load your CentOS box with essential build tools to get started
$ sudo yum groupinstall "Development tools"
Get Java and python dependencies installed
$ sudo yum install java-1.6.0-openjdk.x86_64 java-1.6.0-openjdk-devel.x86_64 python python-devel libcurl libcurl-devel
Get the latest Mesos tarball
$ wget http://mirror.nus.edu.sg/apache/mesos/0.13.0/mesos-0.13.0.tar.gz
$ tar -xzvf mesos-0.13.0.tar.gz
$ cd mesos-0.13.0
Before you can build Mesos, you need to set correct JAVA binding paths
$ export JAVA_HOME=/usr
$ export JAVA_LDFLAGS="-L/usr/lib/jvm/java-1.6.0/jre/lib/amd64/server -R/usr/lib/jvm/java-1.6.0/jre/lib/amd64/server -ljvm"
$ export JAVA_CPPFLAGS="-I/usr/lib/jvm/java-1.6.0/include -I/usr/lib/jvm/java-1.6.0/include/linux"
$ export LD_LIBRARY_PATH=/usr/lib/jvm/java-1.6.0/jre/lib/amd64/server:$LD_LIBRARY_PATH
Configure and build it
$ ./configure
$ make
After you have built Mesos, it is advisable that you build and run the tests, this will make sure that what you have installed meets all the requirements
$ make check
If the checks are successful, You are just one step away from installing it in your system installation paths
$ make install
To learn how to use Mesos , go here http://mesos.apache.org/gettingstarted/
For those who prefer installing from RPM's, here is a link to a number of different releases for different Linux flavors: http://mesosphere.io/downloads/ For example, for Centos64:
wget http://downloads.mesosphere.io/master/centos/6/mesos_0.14.2_x86_64.rpm
sudo rpm -Uvh mesos_0.14.2_x86_64.rpm
I also had to set my LD_LIBRARY_PATH, though to a slightly different value. Check yours.
Python bindings can also be downloaded from the first link above:
wget http://downloads.mesosphere.io/master/centos/6/mesos_0.14.2_x86_64.egg
sudo easy_install mesos_0.14.2_x86_64.egg