Java installation issue using ansible playbook - ansible

I am trying to install the java8 using ansible playbook. Below is the yml file of my playbook:
---
- hosts: test2
become: true
tasks:
- name: install the java pre-requisties
apt:
name: software-properties-common
state: latest
- name: add oracle java repository
apt_repository:
repo: 'ppa:webupd8team/java'
- name: update repository
apt:
update_cache: yes
- name: Accept Java 8 License
debconf:
name: 'oracle-java8-installer'
question: 'shared/accepted-oracle-license-v1-1'
value: true
vtype: 'select'
- name: install java 8
apt:
name: oracle-java8-installer
force: yes
But i am getting the below error:
fatal: [host2]: FAILED! => {"changed": false, "msg": "No package matching 'oracle-java8-installer' is available"}
Can you please help me to fix the issue?
Any assistance will be appreciated.
Thanks in advance.

Possible Network issue with server reaching Repository, Please check locally using apt commands if package can be download.

I tried changing deb_oracle_package: 'oracle-java8-installer' to deb_oracle_package: 'openjdk-8-jre-headless' in my mains.yml for ansible.

Related

Install ngnix on ubuntu 20.04 using ansible playbook?

Hi i am new to ansible i have to deploy nodejs12.8.4, SSL and ngnix latest to Ubuntu 20.04 server can someone guide me how to do it thank you.
this is my yml file:
hosts: all
become: true
tasks:
- name: install nodejs prerequisites
apt:
name:
- apt-transport-https
- gcc
- g++
- make
state: present
- name: add nodejs apt key
apt_key:
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
state: present
- name: add nodejs repository
apt_repository:
repo: deb https://deb.nodesource.com/node_12.x {{ ansible_lsb.codename }} main
state: present
update_cache: yes
- name: install nodejs
apt:
name: nodejs
state: present
it install nodejs 12 now i want to install nginx in same file how i add new task.
Try Ansible NGINX Role. See details at Github.
Q: "I want to install Nginx in the same file how I add a new task?"
A: Include the role
- include_role:
name: nginx
Download the role. See Roles and Using Roles in particular.

Ansible - How to run multiple tasks in a playbook

I'm new to ansible, and am attempting to run multiple tasks to install docker on a particular host group in an ansible playbook.
I have the following playbook...
---
- hosts: all
tasks:
- name: Update and upgrade apt packages
become: yes
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 86400 #One day
- hosts: loadbalancer
become: yes
tasks:
- name: Install docker packages
apt:
name:
- 'apt-transport-https'
- 'ca-certificates'
- 'curl'
- 'software-properties-common'
state: present
- name: Add Docker official GPG key
apt-key:
url: https://download.docker.com/linux/ubuntu/gpg
This is the error I get when attempting to run the playbook...
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to be in '/home/vagrant/ansible/playbooks/hostname.yml': line 23, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Add Docker official GPG key
^ here
What am I doing wrong here?
Thanks,
It is not apt-key, it is apt_key. Please update and try again

Unable to install kubelet from ansible

I'm trying to install kubelet with Ansible, but I'm struggling to do it.
This is my playbook:
---
- hosts: all
become: yes
tasks:
- name: install docker
yum:
name: docker
state: present
update_cache: true
- name: add repo
yum_repository:
name: kuberepo
description: kubernetes-repo
baseurl: "https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64"
enabled: yes
gpgcheck: yes
repo_gpgcheck: yes
gpgkey:
- "https://packages.cloud.google.com/yum/doc/yum-key.gpg"
- "https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg"
- name: setenforce
shell: setenforce 0
- name: install kubelet
yum:
name: kubelet
state: present
update_cache: true
This is the error when i run the playbook (ansible-playbook -i hosts kube-dependencies.yml)
The "ok" from [master] node is because I manually executed "sudo yum install kubelet" on that machine, and it worked.
Conclusions:
So basically, manually executing the yum install command it works, but I can't make it work with ansible.
Any clues? Thanks in advance.
I had the same issue, I fix it adding version of kubelet
apt:
name: kubelet=1.20.0-00
state: present
update_cache: true
That worked for me
same issue with kubeletadm
- name: install kubeadm
apt:
name: kubeadm=1.14.0-00
state: present
Error
solution
- name: install kubeadm
apt:
name: kubeadm=1.20.0-00
state: present
Fix the problem
I hope I've helped
The best solution is to upgrade the version to install.
in every new version k8s changed many configs so some components become npt compatible (kubelet vs kubernetes-cni (= 0.7.5) are not compatible.
version up, if not works then find another solution.
hope that this clarification help.

How to auto accept terms while installing packages with Ansible?

While installing pkgs Ansible fails, because there is a need to accept licensing terms.
How to auto accept terms through ansible-playbook?
---
- hosts: client1
remote_user: ansible
become: True
tasks:
- name: testing
apt_repository: repo=ppa:webupd8team/java state=present
- name: updating
apt: update_cache=yes
- name: installaing oracle pkg
apt: pkg=oracle-java8-installer state=present update_cache=yes
There is no universal method for "packages".
For Oracle Java add a task before calling apt:
- debconf:
name: oracle-java8-installer
question: shared/accepted-oracle-license-v1-1
value: true
vtype: select
For virtualbox-ext-pack
- debconf:
name: virtualbox-ext-pack
question: virtualbox-ext-pack/license
value: "true"
vtype: select
before apt install command.

ERROR: apt is not a legal parameter of an Ansible Play

I'm getting the following error when trying to run a YML file:-
user#ubuntuA:~$ ansible-playbook -i hostfile setup.yml
ERROR:
apt is not a legal parameter of an Ansible Play
Ansible version: 1.9.2
yml-file:-
---
- name: Install MySQL server
apt: name=mysql-server state=latest
- name: Install Apache module for MySQL authentication
apt: name=libapache2-mod-auth-mysql state=latest
- name: Install MySQL module for PHP
apt: name=php5-mysql state=latest
Your yml file should look something like this:
---
- hosts: all
become: yes
tasks:
- name: Install packages
apt:
name:
- mysql-server
- libapache2-mod-auth-mysql
- php5-mysql
state: latest
cache_valid_time: 3600 # update cache if more than an hour old
You are trying to execute your setup.yml file directly with ansible-playbook. As #smiler171 mentioned in his answer, correct format for this is the following:
---
- hosts: all
tasks:
- name: Install MySQL server
apt: name=mysql-server state=latest
- name: Install Apache module for MySQL authentication
apt: name=libapache2-mod-auth-mysql state=latest
- name: Install MySQL module for PHP
apt: name=php5-mysql state=latest
Your current file format is for imports and includes. It is useful if you want to reuse tasks from setup.yml somewhere else. In this case you can create another file (let's say playbook.yml) like that:
---
- hosts: all
tasks:
- import_tasks: setup.yml
and run it:
ansible-playbook -i hostfile playbook.yml
Usually, that means that your playbook yml file does not comply with yml syntax. Check for spaces , hyphen etc. Take a look at existing working yml files, like the one pasted by smiller171 in the above answer. I also had a similar error , turned out that my syntax was incorrect.

Resources