Error while running (docker_image) module ansible Playbook - docker

I have my docker images in nexus. When i am trying to run that playbook i am getting error
Playbook Code
---
- hosts: localhost
become: True
tasks:
- name: pull an image
docker_image:
name: 10.220.110.10:8083/halosys:f5a950f
source: pull
...
ERROR while running my playbook
TASK [pull an image] **************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (docker_image) module: source Supported parameters include: api_version, archive_path, buildargs, cacert_path, cert_path, container_limits, debug, docker_host, dockerfile, force, http_timeout, key_path, load_path, name, nocache, path, pull, push, repository, rm, ssl_version, state, tag, timeout, tls, tls_hostname, tls_verify, use_tls"}
Please help to fix this error

Option source was added in Ansible 2.8 - see documentation. The error message states it is missing, so you're using older version. To fix this you need to either update your Ansible installation to at least version 2.8 or check the documentation for your version.
For example, Ansible 2.7 documentation states that to pull an image you need to do:
- name: pull an image
docker_image:
name: 10.220.110.10:8083/halosys:f5a950f
To check what version of Ansible you're running use command
ansible --version
EDIT:
I can’t guarantee it’ll work, but I would try removing Ansible installed from system packages:
sudo yum remove ansible
followed by installing Python 3:
sudo yum install python36 python36-virtualenv python36-pip
then installing docker-py using pip:
python3 -m pip install docker-py
And finally installing Ansible with Python3 support:
python3 -m pip install ansible
Here’s Ansible documentation about Python3 support.
Also if package python36 is not available you can run
sudo yum list | grep python3
to find what version is available. As per documentation mentioned above you need at least python35 to make Ansible work.

Related

Ansible Docker containers dynamic inventory on MacOS

I have started a Docker container using the following command:
docker run tomcat:latest
Then I created a file named docker.yml with the following contents:
plugin: community.docker.docker_containers
docker_host: unix://var/run/docker.sock
Finally I try to obtain a list of the currently running Docker containers using:
ansible-inventory -i docker.yml --list
However instead of a list of running containers, I only get the following result:
[WARNING]: * Failed to parse docker.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]: * Failed to parse docker.yml with constructed plugin: Incorrect plugin name in file: community.docker.docker_containers
[WARNING]: Unable to parse docker.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
"_meta": {
"hostvars": {}
},
"all": {
"children": [
"ungrouped"
]
}
}
Have I misunderstood the Ansible Docker containers dynamic inventory or am I doing something wrong?
I suspect I had a case of system in disarray and this was the cure:
I retained my current Python installation located at ~/Library/Python/3.9/.
Attempted to uninstall Ansible using pip:
pip uninstall ansible
Manually removed all things Ansible:
sudo rm -r /etc/ansible
sudo rm -r -/.ansible
sudo rm -r /usr/local/lib/python3.9/site-packages/ansible*
sudo rm /usr/local/bin/ansible*
Performed a fresh installation of Ansible:
pip install ez_setup
pip install --user ansible
Installed Ansible Docker collection prerequisite:
pip install docker
Installed Ansible Docker collection:
ansible-galaxy collection install community.docker
After the above, the Ansible Docker container dynamic inventory works as expected and without errors.

gitlab-runner in a custom server

I am trying to setup gitlab-runner in a aws instance.
My project is in a group. Hence setting up group-runner so that I can use it for other projects in the group.
# gitlab-runner version
Version: 11.7.0
Git revision: 8bb608ff
Git branch: 11-7-stable
GO version: go1.8.7
Built: 2019-01-22T11:46:13+0000
OS/Arch: linux/amd64
# docker
Docker version 18.09.1, build 4c52b90
docker-machine version 0.16.0, build 702c267f
Registered the runner with
sudo gitlab-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
Please enter the gitlab-ci token for this runner
<group runner token>
Please enter the gitlab-ci description for this runner
[hostame] my-runner
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
docker
Please enter the Docker image (eg. ruby:2.1):
ruby:2.5
I can see my-runner runner registered from gitlab UI.
Whenever I run/retry the pipeline, it always execute with gitlab's auto-scaling instance.
Running with gitlab-runner 11.7.0-rc1 (6e20bd76)
on docker-auto-scale ed2dce3a
Using Docker executor with image ruby:2.5 ...
Pulling docker image ruby:2.5 ...
Using docker image sha256:feea8cad6f9e7cc58f7ae793ac92bd80fa1ce4da54a381921f161447e978021f for ruby:2.5 ...
Running on runner-ed2dce3a-project-10682917-concurrent-0 via runner-ed2dce3a-srm-1549352595-5d0f29b8...
Cloning repository...
Cloning into '/builds/dr5nn/gitlab-ci-demo'...
Where and what I am missing to run gitlab-runner from my custom machine?
Do I need to add IP address somewhere or enable some port in my aws instance?
Bellow is my .gitlab-ci.yml
before_script:
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
- ruby -v
- which ruby
- gem install bundler -v 2.0.1
- bundle install --jobs $(nproc) "${FLAGS[#]}"
rubocop:
script:
- bundle exec rubocop
You are on right way - all you need is to disable shared gitlab runners for your group or particular project.
Registering group runner enables it for the group, but that doesn't actually disable all other runners - pipeline still chooses the most convenient one based on tags and other criteria.
Other way - use your private tags (not like docker and etc) to select runner. Runners pick their jobs according to the set of tags, specified for jobs. For example, if job has tags docker and linux, only runners with such tags can pick it up. So, you can simply mark jobs, which you want to execute on your group runner (and not on shared runners) with tag like private-runner and add this tag to your runner.
With suggestion from grapes. I'm able to run with bellow configurations.
While registering gitlab-runner from my aws intance
...
...
Please enter the gitlab-ci tags for this runner (comma separated):
my-tag
...
...
And changed gitlab-ci.yml file with
before_script:
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
- ruby -v
- which ruby
- gem install bundler -v 2.0.1
- bundle install --jobs $(nproc) "${FLAGS[#]}"
rubocop:
tags:
- my-tag
script:
- bundle exec rubocop

Salt: 'dockerng' __virtual__ returned False

I have Debian Jessie and I'm trying to manage Docker containers with Salt dockerng. But when I try for example this state:
# file: docker_demo.sls
hello-world:
dockerng.image_present
Then sudo salt '*' state.highstate fails:
----------
ID: hello-world
Function: dockerng.image_present
Result: False
Comment: State 'dockerng.image_present' was not found in SLS 'docker_demo'
Reason: 'dockerng' __virtual__ returned False
Started:
Duration:
Changes:
How can I fix this so dockerng.image_present can pull the image, dockerng.running can run Docker containers etc.?
The dockerng module executed by Salt minion communicates with Docker daemon over REST API using docker-py (not the CLI command docker).
The error message 'dockerng' __virtual__ returned False is a little bit misleading, but if you see the source code, it returns False because it cannot import Pyhon module docker. So this Python package must be installed.
There are packages in Debian repository: python-docker and python3-docker. But both are incompatible with the recent docker-engine (installed from APT repository deb https://apt.dockerproject.org/repo debian-jessie).
So the solution is to uninstall python-docker package if installed and to install the latest docker-py using pip:
sudo apt-get install python-pip
sudo pip install docker-py
Or use this Salt state:
python-pip:
pkg.installed
docker-py:
pip.installed:
- require:
- pkg: python-pip
Or just run
salt myminion pip.install docker-py
The python-docker package from Debian Stretch (now testing, should become Debian stable in 2017) seems to be working OK.

Ansible Docker Module from OSX

I am trying to use the Ansible Docker module at the moment but I am currently encountering this error when I try to run my playbook -
NameError: global name 'DEFAULT_DOCKER_API_VERSION' is not defined
I found an official bug regarding this at https://github.com/ansible/ansible-modules-core/issues/1792.
I have tried the workaround by installing docker-py but have had no joy as of yet.
Any ideas on what could be going wrong? I'm trying to run my Playbook from my local OSX host that connects to AWS.
After further investigation we managed to get it to work by using -
name: Install Docker PY
pip: name=docker-py==1.1.0
In our .yml file
pip is a package manager for python and installs with it. So what you want to do is installing python.
On OS X I recommend you to first install Homebrew, which is a package manager for OS X. The command to install Homebrew is
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After Homebrew is installed you can install python and along with it pip with
brew install python
Normally it is related to the absence of pip or docker-py library.
I have this in my docker ansible role.
- name: install the required packages
apt: pkg={{ item }} state=present update_cache=yes
with_items:
- python-pip
- name: Install docker-py as a workaround for Ansible issue
pip: name=docker-py version=1.2.3
TLDR; -e use_tls=encrypt
I'm using the newest dockerpy==1.5.0
~/.bash_profile I have eval "$(docker-machine env default)" which will run
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/meyers/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
Now that your environment is setup let me tell you the fix. The docker module needs the parameter tls=encrypt. You can supply it to each invocation of the docker module in your Ansible task or you can set it "globally" via -e use_tls=encrypt or in your playbook:
- hosts: all
vars:
use_tls: 'encrypt'
tasks:
...

How to update Jenkins/Hudson through CLI

I have a hudson installed in server's /var/lib/hudson directory. when I access jenkins through URL in my browser,, I see the version 1.411 in the bottom of the page.
Does anybody know how to update Jenkins through command line (CLI). if its possible.
When I go to Manage Jenkins page , it says something like :
"New version of Jenkins (1.521) is available for download (changelog)."
I dont feel safe with downloading the new jar and extract that in the server.
Are you referring to the Jenkins CLI, or the CLI on your operating system ? There is no way to update the Jenkins version via the Jenkins CLI.
If you installed Jenkins as a standalone WAR file, all you need to do to upgrade it from the command line is to download the new Jenkins WAR file and replace your current WAR file, then restart Jenkins. It's always a good idea to back up the full contents of your $JENKINS_HOME directory before upgrading.
If you used a native package such as an RPM or DEB, you should use the package manager on your Jenkins server (yum, apt-get etc.) to upgrade Jenkins.
Since the accepted answer doesn't tell much about upgrading Jenkins by logging into the server itself, I will add how to do that in a server that uses apt package manager.
After logging into the server, type the following command to list down all the packages that are upgradable.
apt list --upgradable
You should get an output like this:
Listing... Done
iproute2/bionic-updates 4.15.0-2ubuntu1.3 amd64 [upgradable from: 4.15.0-2ubuntu1.2]
jenkins/binary 2.277.1 all [upgradable from: 2.263.4]
If Jenkins is in the output list, just simply run the upgrade with the following command:
apt upgrade jenkins
Yes we can update the jenkins by CLI.
Check which jenkins.rpm is being used
$sudo rpm -q jenkins
in my case it was jenkins-2.119-1.1.noarch.
If you don't have jenkins.repo and jenkins key then run following steps
$sudo yum install wget
for installing wget
$sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
$sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
$sudo yum clean metadata
This will remove unused excessive and old metadata
$sudo yum remove jenkins
it will remove jenkins-2.119-1.1.noarch (old version rpm).
Go to jenkins official website page and then copy url of rpm you want
$wget https://get.jenkins.io/redhat/jenkins-2.380-1.1.noarch.rpm
Downloaded required jenkins rpm pkg
$ sudo rpm -i jenkins-2.380-1.1.noarch.rpm
Installed new jenkins rpm
$ sudo rpm -qa jenkins
jenkins-2.380-1.1.noarch
$sudo systemctl enable jenkins
$sudo systemctl start jenkins
here you may get this type of error
"Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe"for details"
for this we have to update the java version we are using to 11 or latest
$sudo yum install fontconfig java-11-openjdk
or
$sudo yum install java-11-openjdk-devel
$sudo update-alternatives --config java
select appropriate version of java
$sudo systemctl start jenkins

Resources