I am new to Ansible and try, as an example, a task to install Vivaldi. My only task in a role Vivaldi update starts with
- name: Run apt upgrade
apt:
upgrade: "yes"
update_cache: yes
cache_valid_time: 432000
- name: Add Vivaldi Repository
apt_repository:
repo: "deb https://repo.vivaldi.com/stable/deb/ stable main"
state: present
filename: vivaldi.list
update_cache: true
tags:
- vivaldi
And with this, I fail on localhost on a DebianĀ 10 (Buster) installation:
Linux london 4.19.0-12-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64 GNU/Linux).
All commands succeed on the command line.
Ansible is 2.9.15.
The first task runs OK (if run alone), but the second fails with:
FAILED! => {"changed": false, "msg": "apt cache update failed"}.
A task to add a repository key fails with:
FAILED! => {"changed": false, "id": "6D3789EDC3401E12", "msg": "key does not seem to have been added"}
However, if I add the repository manually to /etc/apt/sources.list the last task,
- name: Install Vivaldi
apt:
name: vivaldi-stable
update_cache: yes
state: latest
tags:
- vivaldi
it succeeds.
What am I doing wrong?
According to official documentation you need to add the key and later the repository:
Manual setup of the Vivaldi Linux repositories
Edit your playbook with the task Add key:
- name: Run apt upgrade
apt:
upgrade: "yes"
update_cache: yes
cache_valid_time: 432000
- name: Add key
apt_key:
url: https://repo.vivaldi.com/archive/linux_signing_key.pub
state: present
tags:
- vivaldi
- name: Add Vivaldi Repository
apt_repository:
repo: "deb https://repo.vivaldi.com/stable/deb/ stable main"
state: present
filename: vivaldi.list
update_cache: true
tags:
- vivaldi
- name: Install Vivaldi
apt:
name: vivaldi-stable
update_cache: yes
state: latest
tags:
- vivaldi
Related
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.
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.
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.
I have the following ansible playbook:
- hosts: node1
sudo: yes
gather_facts: no
tasks:
- name: update apt
apt: update_cache=yes
- name: install python-setuptools
apt: name=python-setuptools update_cache=yes
- name: easy_install pexpect module
easy_install: name=pexpect state=latest
- name: add geonode repo
apt_repository: repo='ppa:geonode/stable' state=present
- name: update apt
apt: update_cache=yes
- name: install geonode
apt: name=geonode update_cache=yes
- expect:
command: geonode createsuperuser
responses:
(?i)username: 'test'
(?i)email: 'test#test.com'
When I run it I get:
PLAY [node1] *******************************************************************
TASK [update apt] **************************************************************
ok: [node1]
TASK [install python-setuptools] ***********************************************
changed: [node1]
TASK [easy_install pexpect module] *********************************************
changed: [node1]
TASK [add geonode repo] ********************************************************
changed: [node1]
TASK [update apt] **************************************************************
ok: [node1]
TASK [install geonode] *********************************************************
Then it hangs indefinitely.
In the remote node (node1), I checked the dir
/home/vagrant/.ansible/tmp/ansible-tmp-1470059145.13-122191240803512/
run the file inside to see why my task is hanging
vagrant#node1:~/.ansible/tmp/ansible-tmp-1470059145.13-122191240803512$ python apt
and get:
{"msg": "Failed to lock apt for exclusive operation", "failed": true, "invocation": {"module_args": {"dpkg_options": "force-confdef,force-confold", "autoremove": false, "force": false, "name": "geonode", "install_recommends": null, "package": ["geonode"], "purge": false, "allow_unauthenticated": false, "state": "present", "upgrade": null, "update_cache": true, "default_release": null, "only_upgrade": false, "deb": null, "cache_valid_time": null}}}
Do you have any insights?
EDIT 1:
It is all day I'm launching this script and never got it working. As I posted this question, obviously, the script successfully executed till the end in 15 minutes. I launched it before lunch today and after 1 hour it was still hanging. Why do I get such a different behaviour? Is there a way in which I can control it?
This issue might be caused by an empty /var/lib/apt folder.
Vagrant might take a while to populate these folders which could cause the apt lock.
Also the playbook is inefficient as update_cache is used multiple times. I would recommend to use something like this:
- hosts: node1
sudo: yes
gather_facts: no
tasks:
# Pause for 5 minutes to make sure vagrant does not hold apt lock.
- pause:
minutes: 5
- name: add geonode repo
apt_repository:
repo: 'ppa:geonode/stable'
state: present
- name: Install apt packages.
apt:
name: "{{ item }}"
state: present
update_cache: true
with_items:
- python-setuptools
- geonode
- name: Create geonode superuser.
expect:
command: geonode createsuperuser
responses:
(?i)username: 'test'
(?i)email: 'test#test.com'
This way Ansible won't update the repositories multiple times during the play.
Since the last thing you see is TASK [install geonode], that's where it's getting stuck.
You are asking it to run geonode createsuperuser which you expect to cause a prompt for username and password.
But what is likely happening is that there is an error being produced from that command, and the expect task is not handling the error, instead just hanging.
You can login to the server you are running this against and run the geonode createsuperuser command manually to see what error is being produced.
In my case, this was happening as a result of the username already being taken since I successfully ran the command on this machine already.
Error: That username is already taken.
Even with the echo: yes argument, ansible doesn't seem to pass on the responses to make it obvious what's happening. And it doesn't accept ignore_errors, so there seems to be no way to handle errors with the expect module.
To work around this, I added another task after the createsuperuser task which places a file in the project indicating the user was created once, and then added creates: {{ path }}/superuser_exists.txt to the createsuperuser task so that it won't run if that file is already there.
It's a hack, but an easy one, and until the module gets better error handling, it will work well enough.
- name: Create the django superuser
expect:
command: "{{ virtualenv_path }}/bin/python3 {{ project_path }}/{{ api_app_name }}/manage.py createsuperuser"
creates: "{{ project_path }}/{{ api_app_name }}/superuser_exists.txt"
responses:
(?i)username: "{{ superuser_username }}"
(?i)email: "{{ superuser_email }}"
(?i)password: "{{ superuser_password }}"
(?i)again: "{{ superuser_password }}"
- name: Create a file to indicate that the superuser was already created
file: path="{{ project_path }}/{{ api_app_name }}/superuser_exists.txt" state=touch
I have a private Docker registry runnning in 172.20.20.20 in port 5000. And I have pushed the image pruebasjeje to it.
Now, I need to pull and run the image using Ansible task:
- name: run container
docker:
registry: 172.20.20.20:5000
insecure_registry: true
image: pruebasjeje
state: reloaded
pull: always
ports:
- "8080:8080"
But when I execute it, I get this error:
fatal: [localhost]: FAILED! => {"changed": false, "changes":
["{\"status\":\"Pulling repository
docker.io/library/pruebasjeje\"}\r\n",
"{\"errorDetail\":{\"message\":\"Error: image
library/pruebasjeje:latest not found\"},\"error\":\"Error: image
library/pruebasjeje:latest not found\"}\r\n"], "failed": true, "msg":
"Unrecognized status from pull.", "status": ""}
It seems that is looking for the image in docker.io. How should I write my task in order to do what I want?
Thanks.
Not sure if it is how it should be done, but this is how I do it:
- name: run container
docker:
insecure_registry: true
image: 172.20.20.20:5000/pruebasjeje
state: reloaded
pull: always
ports:
- "8080:8080"
I just started with Docker myself. Here are the tasks I have for setting up Docker on my target host (CentOS 7):
- name: Install epel repo
yum:
name: "http://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_userspace_architecture }}{{ '/' if ansible_distribution_major_version < '7' else '/e/' }}epel-release-{{ ansible_distribution_major_version }}-5.noarch.rpm"
state: present
become: yes
- name: Install Docker
yum:
name: "{{ item }}"
state: latest
enablerepo: epel
with_items:
- device-mapper
- docker-engine
- python-pip
become: yes
- name: Install docker-py
pip:
name: docker-py
become: yes
- name: Add registry cert
copy:
src: registry.crt
dest: /etc/docker/certs.d/{{ docker_registry_host }}/ca.crt
become: yes
- name: Allow access to insecure registry
lineinfile:
dest: /usr/lib/systemd/system/docker.service
regexp: ^ExecStart=
line: ExecStart=/usr/bin/docker daemon -H fd:// --insecure-registry {{ docker_registry_host }}:5000
become: yes
- name: Start Docker service
service:
name: docker
state: started
enabled: yes
become: yes