Ok, It is my task:
---
- name: copy source list
copy: src=sources.list dest=/etc/apt/sources.list
notify: update apt
# - name: Update apt
# shell: apt-get update
- name: Install postgres
shell: apt-get install -q -y postgresql-9.1
#apt: name=postgresql-9.1 state=present
- others tasks...
Here is my handler:
- name: update apt
action: apt-get update
When I run it doesn't notify.
...
TASK: [postgresql | copy source list] *****************************************
changed: [host_slave2]
changed: [host_slave1]
changed: [host_pgpool]
changed: [host_master]
TASK: [postgresql | Install postgres] *****************************************
changed: [host_slave1]
changed: [host_master]
changed: [host_slave2]
changed: [host_pgpool]
...
After the copy I should have to see the notification, what is wrong?
---
- name: copy source list
copy: src=sources.list dest=/etc/apt/sources.list
#http://docs.ansible.com/apt_repository_module.html
register: update_apt
- name: Update apt
apt: update_cache=yes cache_valid_time=86400
#http://docs.ansible.com/apt_module.html
when: update_apt is defined and update_apt.changed == True
- name: Install postgres
shell: apt-get install -q -y postgresql-9.1
#apt: name=postgresql-9.1 state=present
- others tasks...
http://wherenow.org/ansible-handlers/
In fact the issue is necessary to force the implementation of
---
- name: copy source list
copy: src=sources.list dest=/etc/apt/sources.list
notify: update apt
- meta: flush_handlers
- name: Install postgres
shell: apt-get install -q -y postgresql-9.1
#apt: name=postgresql-9.1 state=present
- others tasks...
handler:
- name: update apt
action: apt-get update
Related
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
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.
For the first time I am trying to use Ansible . When I tried to run a playbook I got this error:
ERROR! this task 'apt_repository' has extra params, which is only allowed in the following modules: command, shell, script, include, include_vars, add_host, group_by, set_fact, raw, meta
The error appears to have been in '/home/prism/Desktop/ansible/basic_package/main.yml': line 9, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: "Add Webupd8 ppa for youtube-dl"
^ here
main.yml :
---
- hosts: all
remote_user: root
tasks:
- name: "Upgrade the whole system"
apt: upgrade=dist update_cache=yes
- name: "Add Webupd8 ppa for youtube-dl"
apt_repository: repo ='ppa:nilarimogard/webupd8'
- name: "Install basic package"
apt: name={{ item }} state=installed
with_items:
- libffi-dev
- vnstat
- youtube-dl
- finger
- htop
- python3-dev
- axel
- curl
- fail2ban
- python-dev
- sendmail
- git
- python-software-properties
- software-properties-common
- python-pip
- nethogs
- unzip
- nmap
Looks like you have an extra space after repo parameter in the apt_repository task. Use the below code:
apt_repository: repo='ppa:nilarimogard/webupd8'
I am configuring a mesos-marathon cluster.
I have the next role to install java and mesos.
---
- name: importar key Mesosphere
shell: gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E56151BF
- name: ppa java8
apt_repository: repo='ppa:webupd8team/java' state=present
- name: seleccionar licencia Oracle
shell: echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
- name: actualizar
apt: update_cache=yes
- name: instalar java8
apt: name=oracle-java8-installer state=latest update-cache=yes force=yes
- name: actualizar sources list
shell: DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]') && CODENAME=$(lsb_release -cs) && echo "deb http://repos.mesosphere.io/${DISTRO} ${CODENAME} main" | sudo tee /etc/apt/sources.list.d/mesosphere.list
- name: actualizar paquetes
apt: update_cache=yes cache_valid_time=3600
- name: instalar mesos
apt: name=mesos state=present install_recommends=yes force=yes
- name: instalar mesosphere
apt: name=mesosphere state=present install_recommends=yes force=yes
My problem is that when I execute the playbook, it gives me the next error:
TASK [common : actualizar sources list] ****************************************
changed: [172.16.8.191]
TASK [common : actualizar paquetes] ********************************************
ok: [172.16.8.191]
TASK [common : instalar mesos] *************************************************
fatal: [172.16.8.191]: FAILED! => {"changed": false, "failed": true, "msg": "No package matching 'mesos' is available"}
PLAY RECAP *********************************************************************
172.16.8.191 : ok=8 changed=5 unreachable=0 failed=1
But if I execute ansible for a second time it works perfectly you can see executing a second time:
TASK [common : actualizar paquetes] ********************************************
ok: [172.16.8.191]
TASK [common : instalar mesos] *************************************************
changed: [172.16.8.191]
TASK [common : instalar mesosphere] ********************************************
changed: [172.16.8.191]
What could be the problem?
Thanks.
SOLUTION BY #ydaetskcoR
Change the task 'instalar mesos':
- name: instalar mesos
apt: name=mesos state=present install_recommends=yes update_cache=yes force=yes
The issue you have is that the actualizar paquetes task is only doing an apt-get update to refresh your repo lists if the last update was more than an hour ago.
Considering you've only just added the Mesos repo in the previous task you won't then be able to find the package. Re-running the playbook triggers the actualizar task before that which doesn't have a cache_valid_time setting and so will force an apt-get update which will then allow you to use the Mesos repo that you added in the last playbook run.
To fix it you could just remove the cache_valid_time from the actualizar paquetes task.
As mentioned in the comments, you can also move the update_cache only apt tasks into the main apt task that actually installs packages and Ansible will run the apt-get update before the apt-get install.
I need to set-up my server. I've the following ansible playbook.
---
- hosts: webservers
user: root
sudo: yes
tasks:
- name: add nginx ppa
action: apt_repository repo=ppa:nginx/stable state=present
- name: install common packages needed for python application development
action: apt pkg=$item state=installed
with_items:
- libpq-dev
- libmysqlclient-dev
- libxml2-dev
- libxslt1-dev
- mysql-client
- python-dev
- python-setuptools
- python-mysqldb
- build-essential
- git
- nginx
- name: install pip
action: easy_install name=pip
- name: install various libraries with pip
action: pip name=$item state=present
with_items:
- uwsgi
handlers:
- name: restart nginx
service: name=nginx state=restarted
When I run this script, following is the output
PLAY [webservers] *************************************************************
GATHERING FACTS ***************************************************************
ok: [IP]
TASK: [add nginx ppa] *********************************************************
ok: [IP]
TASK: [install common packages needed for python application development] *****
failed: [IP] => (item=libpq-dev,libmysqlclient-dev,libxml2-dev,libxslt1-dev,mysql-client,python-dev,python-setuptools,python-mysqldb,build-essential,git,nginx) => {"failed": true, "item": "libpq-dev,libmysqlclient-dev,libxml2-dev,libxslt1-dev,mysql-client,python-dev,python-setuptools,python-mysqldb,build-essential,git,nginx"}
msg: No package matching '$item' is available
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit #/home/praful/setup_server.yaml.retry
IP : ok=2 changed=0 unreachable=0 failed=1
I've referred this link for the same.
I'm new to ansible and dont understand the error, since there is no typo in the package name provided in with_items. What exactly is the error??
You need the jinja variable syntax {{item}} where you have $item.