Install multiple yum packages on Centos(node) via Ansible? - ansible
Here is the part of YAMLcode that i am trying to run on a node which has operating system, Centos-7......
file hierarchy is
--> roles/install_tools/tasks/main.yml
its not working fine, YAML syntax is also valid and correct !
Could someone help me ?
---
- name: install the Development tools package group
yum:
name: "#Development tools"
state: present
- name: Install common software requirements
ignore_errors: yes
become: true
yum: pkg={{ item }} state=present
with_items:
- yum-plugin-fastestmirror
- epel-release
- git
- libyaml-devel
- libnet-devel
- libnetfilter_queue-devel
- libpcap-devel
- pcre-devel
- file-devel
- jansson-devel
- nss-devel
- libcap-ng-devel
- lua-devel
- binutils
- gmp
- gmp-devel
- make
- ld
- glibc.i686
- python-pip
- perl-Sys-Syslog
- readline-devel
- ncurses-devel
- openssl-devel
- easy-rsa
- flex
- bison
- pcre
- zlib
- zlib-devel
- libpcap
- libdnet
- libdnet-devel
- m4
- gcc
- mysql-devel
- python-devel
- geoip
- geoip-devel
- libffi-devel
- vim
- lsof
- wget
- mlocate
- htop
- net-tools
- traceroute
- tcpdump
- radiusclient-ng.x86_64
- gmp-devel
- iptables-services
- dnsmasq
- pptpd
- mariadb-devel
- lzo-devel.x86_64
- crontabs
- gcc
- make
- rpm-build
- autoconf.noarch
- zlib-devel
- pam-devel
- openssl-devel
The error it is showing is;
TASK [install_tools : Install common software requirements] ***********************
failed: [meracentos] (item=[u'yum-plugin-fastestmirror', u'epel-release', u'git', u'libyaml-devel', u'libnet-devel', u'libnetfilter_queue-devel', u'libpcap-devel', u'pcre-devel', u'file-devel', u'jansson-devel', u'nss-devel', u'libcap-ng-devel', u'lua-devel', u'binutils', u'gmp', u'gmp-devel', u'make', u'ld', u'glibc.i686', u'python-pip', u'perl-Sys-Syslog', u'readline-devel', u'ncurses-devel', u'openssl-devel', u'easy-rsa', u'flex', u'bison', u'pcre', u'zlib', u'zlib-devel', u'libpcap', u'libdnet', u'libdnet-devel', u'm4', u'gcc', u'mysql-devel', u'python-devel', u'geoip', u'geoip-devel', u'libffi-devel', u'vim', u'lsof', u'wget', u'mlocate', u'htop', u'net-tools', u'traceroute', u'tcpdump', u'radiusclient-ng.x86_64', u'gmp-devel', u'iptables-services', u'dnsmasq', u'pptpd', u'mariadb-devel', u'lzo-devel.x86_64', u'crontabs', u'gcc', u'make', u'rpm-build', u'autoconf.noarch', u'zlib-devel', u'pam-devel', u'openssl-devel']) => {"changed": false, "failed": true, "item": ["yum-plugin-fastestmirror", "epel-release", "git", "libyaml-devel", "libnet-devel", "libnetfilter_queue-devel", "libpcap-devel", "pcre-devel", "file-devel", "jansson-devel", "nss-devel", "libcap-ng-devel", "lua-devel", "binutils", "gmp", "gmp-devel", "make", "ld", "glibc.i686", "python-pip", "perl-Sys-Syslog", "readline-devel", "ncurses-devel", "openssl-devel", "easy-rsa", "flex", "bison", "pcre", "zlib", "zlib-devel", "libpcap", "libdnet", "libdnet-devel", "m4", "gcc", "mysql-devel", "python-devel", "geoip", "geoip-devel", "libffi-devel", "vim", "lsof", "wget", "mlocate", "htop", "net-tools", "traceroute", "tcpdump", "radiusclient-ng.x86_64", "gmp-devel", "iptables-services", "dnsmasq", "pptpd", "mariadb-devel", "lzo-devel.x86_64", "crontabs", "gcc", "make", "rpm-build", "autoconf.noarch", "zlib-devel", "pam-devel", "openssl-devel"], "msg": "No package matching 'ld' found available, installed or updated", "rc": 126, "results": ["yum-plugin-fastestmirror-1.1.31-40.el7.noarch providing yum-plugin-fastestmirror is already installed", "git-1.8.3.1-6.el7_2.1.x86_64 providing git is already installed", "binutils-2.25.1-22.base.el7.x86_64 providing binutils is already installed", "gmp-1:6.0.0-12.el7_1.x86_64 providing gmp is already installed", "make-1:3.82-23.el7.x86_64 providing make is already installed", "No package matching 'ld' found available, installed or updated"]}
Use of with_items with the ansible yum is now deprecated. You should pass a list to name: as follows;
- name: Install common software requirements
become: true
yum:
state: present
name:
- yum-plugin-fastestmirror
- epel-release
- git
- libyaml-devel
- libnet-devel
- libnetfilter_queue-devel
- libpcap-devel
- pcre-devel
- file-devel
- jansson-devel
- nss-devel
- libcap-ng-devel
- lua-devel
- binutils
- gmp
- gmp-devel
- make
- ld
- glibc.i686
- python-pip
- perl-Sys-Syslog
- readline-devel
- ncurses-devel
- openssl-devel
- easy-rsa
The previous solution will give you the following error:
Invoking "yum" only once while using a loop via squash_actions is deprecated. Instead of using a loop to supply multiple items and specifying `name: {{ item }}`,
Below code worked for me -->
File - yumInstall.yml
---
- hosts: localhost
gather_facts: False
serial: 1
tasks:
- name: 1. Install Apache Packages
yum: name={{ item }} state=present
with_items:
- httpd
- yum-plugin-fastestmirror
- epel-release
- git
- libyaml-devel
- libnet-devel
- libnetfilter_queue-devel
- libpcap-devel
- pcre-devel
- file-devel
- jansson-devel
- nss-devel
- libcap-ng-devel
- lua-devel
- binutils
- gmp
- gmp-devel
- make
# - ld
- glibc.i686
- python-pip
- perl-Sys-Syslog
- readline-devel
- ncurses-devel
- openssl-devel
- easy-rsa
- flex
- bison
- pcre
- zlib
- zlib-devel
Executing playbook:-
ansible-playbook -i hosts yumInstall.yml
[WARNING]: Found both group and host with same name: localhost
PLAY [localhost] *****************************************************************************************************************************************************************
TASK [1. Install Apache Packages] ************************************************************************************************************************************************
changed: [localhost] => (item=[u'httpd', u'yum-plugin-fastestmirror', u'epel-release', u'git', u'libyaml-devel', u'libnet-devel', u'libnetfilter_queue-devel', u'libpcap-devel', u'pcre-devel', u'file-devel', u'jansson-devel', u'nss-devel', u'libcap-ng-devel', u'lua-devel', u'binutils', u'gmp', u'gmp-devel', u'make', u'glibc.i686', u'python-pip', u'perl-Sys-Syslog', u'readline-devel', u'ncurses-devel', u'openssl-devel', u'easy-rsa', u'flex', u'bison', u'pcre', u'zlib', u'zlib-devel'])
PLAY RECAP ***********************************************************************************************************************************************************************
localhost : ok=1 changed=1 unreachable=0 failed=0
You can use simple list:
- name: Ensure useful util libs are present
yum:
name: ['httpie', 'the_silver_searcher', 'fasd', 'multitail', 'vim']
state: present
become: True
or as yaml list
- name: Ensure useful util libs are present
yum:
name:
- httpie
- the_silver_searcher
- fasd
- multitail
- vim
state: present
become: True
there is two errors in your config.
yum syntax error
with_items is deprecated now.
example:
- name: Install Tools
yum:
state: present
name:
- telnet
- htop
Related
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.
YAML syntax error (Ansible playboook)
I am trying to write a playbook that installs Apache, but I get the below error: The offending line appears to be: tasks: - name: command to install apache ^ here Here is my YAML code: --- - hosts: all tasks: - name: command to install apache sudo: yes yum: name=httpd state=latest service: name=httpd state=running What could be wrong here?
You cannot add two actions (modules) to a single task in Ansible. You need to split yum and service into two tasks. Also sudo declaration was deprecated long time ago and now become should be used: --- - hosts: all tasks: - name: Ensure apache is installed become: yes yum: name=httpd state=latest - name: Ensure httpd service is running become: yes service: name=httpd state=running
Why Ansible keeps giving me error "Could not find the requested service httpd: cannot check nor set state"?
I am doing a dry run on installing apache web server on a centos 7 box. This is the webserver.yml file: --- # Outline to Playbook Translation - hosts: apacheWeb user: aleatoire sudo: yes gather_facts: no tasks: - name: date/time stamp for when the playbook starts raw: /bin/date > /home/aleatoire/playbook_start.log - name: install the apache web server yum: pkg=httpd state=latest - name: start the web service service: name=httpd state=started - name: install client software - telnet yum: pkg=telnet state=latest - name: install client software - lynx yum: pkg=lynx state=latest - name: log all the packages installed on the system raw: yum list installed > /home/aleatoire/installed.log - name: date/time stamp for when the playbook ends raw: /bin/date > /home/aleatoire/playbook_end.log When I do a dry run with: ansible-playbook webserver.yml --check I keep getting this error: fatal: [<ip_address>]: FAILED! => {"changed": false, "failed": true, "msg": "Could not find the requested service httpd: cannot check nor set state"} to retry, use: --limit #/home/aleatoire/Outline/webserver.retry I tried adding ignore_issues: true and that did not work either.
--check is not going to actually install the httpd package if it's not there yet. So then the service: call will fail if there is no httpd unit file installed yet. You can use --syntax-check option instead.
ERROR! this task 'apt_repository' has extra params
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'
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.