Ansible Yum module - ansible-facts

'''Could not detect which major revision of yum is in use, which is required to determine module backend.", "You should manually specify use_backend to tell the module whether to use the yum (yum3) or dnf (yum4) backend
---
- hosts: all
become: yes
vars:
node_apps_location: /usr/local/opt/node
tasks:
- name: Ensure NTP (for time synchronization) is installed.
yum: name=ntp state=present
- name: Ensure NTP is running.
service: name=ntpd state=started enabled=yes
- name: Install EPEL repo.
yum: name=epel-release state=present
- name: Import Remi GPG key.
rpm_key:
key: "https://rpms.remirepo.net/RPM-GPG-KEY-remi"
state: present
- name: Install Remi repo.
yum:
name: "https://rpms.remirepo.net/enterprise/remi-release-7.rpm"
state: present
getting
Could not detect which major revision of yum is in use, which is required to determine module backend.", "You should manually specify use_backend to tell the module whether to use the yum (yum3) or dnf (yum4) backend
When i run ansible-playbook

Related

Installing dependencies with conan on github actions takes too long

I have built a Github workflow that installs Conan to manage a bunch of C++ dependencies along with CMake. It works great and I can test that:
my environment works
my library builds
tests pass
at every commit.
However, it is not very convenient for repeated pushes, as the Conan install dependencies step takes too long. Is there a way to:
Bypass the Conan installation and reuse previous workspace if dependencies are unchanged (that is, most of the time)
If not, what is the "standard" to have an equivalent system configuration in place on my system for tests (Does Conan has a Python virtual environment equivalent, or should I use a Docker, or ... ?)
My workflow is the following:
name: CMake
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work
# equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team#latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
fetch-depth: 0
- name: Get GCC-10
run: |
sudo apt update
sudo apt install gcc-10 g++-10
shell: bash
- name: Install Doxygen
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends doxygen graphviz
- name: Conan installation
id: conan
uses: turtlebrowser/get-conan#v1.0
- name: Conan version
run: echo "${{ steps.conan.outputs.version }}"
- name: Create default Conan profile
run: conan profile new default --detect
- name: Conan configure remotes
run: |
conan remote add bincrafters https://bincrafters.jfrog.io/artifactory/api/conan/public-conan
conan config set general.revisions_enabled=1
- name: Conan profile update
run: |
conan profile update settings.compiler=gcc default
conan profile update settings.compiler.version=10 default
conan profile update settings.compiler.cppstd=20 default
conan profile update env.CC=[/usr/bin/gcc-10] default
conan profile update env.CXX=[/usr/bin/g++-10] default
conan profile update conf.tools.cmake.cmaketoolchain:generator=Ninja default
conan profile show default
- name: Conan install dependencies
run: |
conan install . \
-s build_type=${{env.BUILD_TYPE}} \
--install-folder=${{github.workspace}}/build \
-pr default \
-b=missing
- name: CMake configuration
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: |
cmake -B ${{github.workspace}}/build \
-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
shell: bash
env:
CC: gcc-10
CXX: g++-10
- name: Cmake build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Cmake test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
- name: Doxygen documentation generation
working-directory: ${{github.workspace}}/build
run: make doc
- name: Documentation moving generated files
run: mv ${{github.workspace}}/build/doc/html ./doc/api
- name: Documentation deploy to Github Pages
uses: peaceiris/actions-gh-pages#v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc/api

store output of command in variable in ansible

Concerning: Ansible-Playbooks
Is it possible to run a command on the remote machine and store the resulting output into a variable?
I am trying to get the kernel version and install the matching headers like this:
---
- hosts: all
tasks:
- name: install headers
become: yes
become_method: sudo
apt:
name: "{{ packages }}"
vars:
packages:
- linux-headers-`uname -r`
#- a lot of other packages here
Unfortunately uname -r is not executed here.
I am aware of this question: Ansible: Store command's stdout in new variable?
But it looks like this is another topic.
By definition:
Ansible facts are data related to your remote systems, including
operating systems, IP addresses, attached filesystems, and more.
In this link you can see all ansible facts that you can use.
https://docs.ansible.com/ansible/latest/user_guide/playbooks_vars_facts.html
One of those variables is ansible_kernel, this is the version of the kernel of your remote system. By default ansible gets this variables, but if you want to be sure that ansible will get this variables you have to use gather_facts: yes.
---
- hosts: all
gather_facts: yes
tasks:
- name: install
become: yes
become_method: sudo
apt:
name: "{{ packages }}"
vars:
packages:
- linux-headers-{{ ansible_kernel }}
I found a solution but I am not sure if this is really elegant
---
- hosts: all
tasks:
- name: Getting Kernel Version
command: "uname -r"
register: kernel_version
- name: install
become: yes
become_method: sudo
apt:
name: "{{ packages }}"
vars:
packages:
- linux-headers-{{ kernel_version.stdout }}

Installing Xfce on CentOS 7 via ansible yum

I have a Centos 7 machine freshly started from the centos/7 vagrant base box. I provision the box via ansible but the following does not work:
- name: Install xfce
yum:
name: "#^Xfce"
state: present
enablerepo: "epel"
The error is:
TASK [desktop : Install xfce]
************************************************** fatal: [xxx]: FAILED! => {"changed": false,
"changes": {"installed": ["#^Xfce"]}, "msg": "Error: Nothing to do\n",
"rc": 1, "results": ["Loaded plugins: fastestmirror\nLoading mirror
speeds from cached hostfile\n * base: mirror.ratiokontakt.de\n * epel:
mirror.de.leaseweb.net\n * extras: centos.schlundtech.de\n * updates:
centos.schlundtech.de\nGroup Xfce does not exist.\n"]}
Yet, running the following command from within the machine works:
sudo yum --enablerepo=epel -y groups install "Xfce"
What am I doing wrong?
According to the yum module documentation:
Yum itself has two types of groups. “Package groups” are specified in the rpm itself while “environment groups” are specified in a separate file (usually by the distribution). Unfortunately, this division becomes apparent to ansible users because ansible needs to operate on the group of packages in a single transaction and yum requires groups to be specified in different ways when used in that way. Package groups are specified as “#development-tools” and environment groups are “#^gnome-desktop-environment”. Use the “yum group list hidden ids” command to see which category of group the group you want to install falls into.
You're specifying your grouop as #^Xfce, which is the syntax for an "environment group", but if you look at the output of yum group list hidden ids there is no "Xfce" environment group. There is a package group by that name, and this playbook seems to install it successfully:
---
- hosts: localhost
gather_facts: false
tasks:
- name: install xfce
yum:
name: "#Xfce"
state: "present"
enablerepo: "epel"

Installing kubectl

Iam getting a message as No package kubectl available while installing kubectl
I have followed the documentation mentioned here
for CentOS VERSION="7 (Core)" , Linux kernel version = 3.10.0-862.14.4.el7.x8
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
yum search kubectl
yum install -y kubectl
when it is executing the command yum search kubectl it is giving the following logs
yum -y search kubectl
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirror.ancl.hawaii.edu
* epel: fedora-epel.mirrors.tds.net
* extras: centos-distro.1gservers.com
* updates: centos.mirror.lstn.net
Retrieving key from https://packages.cloud.google.com/yum/doc/yum-key.gpg
Importing GPG key 0x.......(some value):
Userid : "Google Cloud Packages RPM Signing Key <gc-team#google.com>"
Fingerprint: xxxx xxxx ... (some value)
From : https://packages.cloud.google.com/yum/doc/yum-key.gpg
Retrieving key from https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
=============================== Matched: kubectl ===============================
kubernetes-client.x86_64 : Kubernetes client tools
$ yum install -y kubectl
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirror.ancl.hawaii.edu
* epel: fedora-epel.mirrors.tds.net
* extras: centos-distro.1gservers.com
* updates: centos.mirror.lstn.net
No package kubectl available.
Error: Nothing to do
I think it is not retrieving the key from "https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg"
The package is clearly available from that repository, so we just need to check your configuration to make sure we can install it.
<package pkgid="3d5dd3e6a783afcd660f9954dec3999efa7e498cac2c14d63725fafa1b264f14" name="kubectl" arch="x86_64"><version epoch="0" ver="1.15.0" rel="0"/><file>/usr/bin/kubectl</file></package>
Source: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/filelists.xml
I would first check that A)/etc/yum.repos.d/kubernetes.repo actually exists, and B) that the contents match, i.e., via cat /etc/yum.repos.d/kubernetes.repo.
Next, both of the commands below can be used to search for the kubectl package.
# Using search
yum search kubectl
# Using grep
yum list | grep kubectl
For importing the GPG key for use with yum, see the following answer:
https://unix.stackexchange.com/q/337257/247886
Try with this:
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
yum install -y kubelet kubeadm kubectl
You may also try to install a specific version by executing: yum install -y kubelet-<version> kubectl-<version> kubeadm-<version>
Always make sure your versions satisfy dependency requirements.
If you have some older versions, uninstall them first.
You may also consider using kubeadm init.
Please let me know if that helped.
Ideally it should work with kubernetes.repo file also but it didn't work in my case. So installed using below steps from the official documentation and it was successful.
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

ansible installing npm using nvm but returning npm command not found on npm install

I am trying to install npm with nvm using ansible playbook script on Ubuntu 18.04.2 LTS. It is getting installed but on running npm install command it returning an error ["/bin/bash: npm: command not found"]
this is the script
- name: Create destination dir if it does not exist
file:
mode: 0775
path: "/usr/local/nvm"
state: directory
when: "nvm_dir != ''"
- name: Install NVM
shell: "curl https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | NVM_SOURCE="" NVM_DIR=/usr/local/nvm PROFILE=/root/.bashrc bash"
args:
warn: false
register: nvm_result
This is the repository where I get the code (https://github.com/morgangraphics/ansible-role-nvm)
By default shell module uses /bin/sh unless the executable has been explicitly defined in the module using args/keyword.
Seems like /bin/bash(a variation of shell is not is installed on the host) thereby giving error. Script needs bin/bash.
bin/bash is mostly installed on all the operating systems. May be some path issue.
Also updated the code below with condition.
---
- hosts: localhost
tasks:
- name: Create destination dir if it does not exist
file:
mode: 0775
path: "/usr/local/nvm"
state: directory
when: "nvm_dir is not defined"
- name: Install NVM
shell: 'curl https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | NVM_SOURCE="" NVM_DIR=/usr/local/nvmPROFILE=/root/.bashrc bash'
args:
warn: false
register: nvm_result