以下是我试图在具有操作系统Centos-7 ......的节点上运行的YAMLcode的一部分......
文件层次结构是 - >角色/ install_tools /任务/ main.yml
它不能正常工作,YAML语法也有效且正确!
有人可以帮助我吗?
---
- 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
它显示的错误是;
任务[install_tools:安装通用软件要求] *********************** 失败:[meracentos](item = [u' yum-plugin-fastermirror',u' epel-release',u' git',u' libyaml-devel&# 39;,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& #39;,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&# 39; 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& #39;,u' mlocate&#3 9;,u' htop',u' net-tools',u' traceroute',u' tcpdump',u' radiusclient-ng.x86_64& #39;,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'] )=> {"更改":false,"失败":true," item":[" yum-plugin-fastermirror"," epel-release"," git"," libyaml-devel"," libnet-devel"," libnetfilter_queue-devel",& #34; libpcap-devel"," pcre-devel"," file-devel"," jansson-devel"," nss-devel& #34;," libcap-ng-devel"," lua-devel"," binutils"," gmp"," gmp-devel"," make"," ld"," glibc.i686"," python-pip",&#34 ; perl-Sys-Syslog"," readline-devel"," ncurses-devel"," openssl-devel"," easy-rsa& #34;," flex"," bison"," pcre"," zlib"," zlib-devel" ," libpcap"," libdnet"," libdnet-devel"," m4"," gcc",&# 34; 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&#34 ;," lzo-devel.x86_64"," crontabs"," gcc"," make"," rpm-build&# 34;," autoconf.noarch"," zlib-devel"," pam-devel"," openssl-devel"],&# 34; msg":"没有包装匹配' ld'发现可用,安装或更新"," rc":126,"结果":[" yum-plugin-fastermirror-1.1.31-40.el7.noarch提供yum-plugin-fastermirror已经安装"," git-1.8.3.1-6.el7_2.1.x86_64提供git已经安装"," binutils-2.25.1-22已经安装了.base.el7.x86_64提供binutils"," gmp-1:6.0.0-12.el7_1.x86_64,已经安装了gmp"," make-1:3.82 -23.el7.x86_64提供make已经安装","没有包匹配' ld'发现可用,已安装或更新"]}
答案 0 :(得分:3)
不建议将with_items
与ansible yum一起使用。您应该按照以下方式将列表传递给name:
;
- name: Install common software requirements
become: true
state: present
yum:
- 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
以前的解决方案将给您以下错误:
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 }}`,
答案 1 :(得分:1)
下面的代码对我有用 - >
文件 - 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
执行剧本: -
ansible-playbook -i hosts yumInstall.yml
[警告]:找到具有相同名称的组和主机:localhost
播放[localhost] ******************************************* ************************************************** ************************************************** ******************
任务[1。安装Apache软件包] ********************************************** ************************************************** ************************************************ 已更改:[localhost] => (item = [u' httpd',u' yum-plugin-fastermirror',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&# 39;,u' openssl-devel',u' easy-rsa',u' flex',u' bison',u' pcre&#39 ;,你' zlib',你' zlib-devel'])
回放********************************************* ************************************************** ************************************************** ********************** localhost:ok = 1 changed = 1 unreachable = 0 failed = 0
答案 2 :(得分:0)
您的配置中有两个错误。
示例:
- name: Install Tools
yum:
state: present
name:
- telnet
- htop
答案 3 :(得分:0)
您可以使用简单的列表:
- name: Ensure useful util libs are present
yum:
name: ['httpie', 'the_silver_searcher', 'fasd', 'multitail', 'vim']
state: present
become: True
或作为Yaml列表
- name: Ensure useful util libs are present
yum:
name:
- httpie
- the_silver_searcher
- fasd
- multitail
- vim
state: present
become: True