这正是我想要实现的目标。我必须与Dependencies一起安装包。我正在尝试安装telnet包。为此,必须按照我的要求安装两个软件包,即telnet和telnet -server。在某些服务器中,已经安装了telnet,但没有安装telnet-server。如果已经安装了telnet软件包,那么如果我在提示符下传递telnet- *,则不会安装telnet-server。以下是剧本执行
[test@localhost ansible]$ cat prompt.yml
--- # Install the package which is provided through command line
- hosts: target
user: test
become: yes
connection: ssh
gather_facts: no
vars_prompt:
- name: pkgtoinstall
prompt: which package need to install?
private: no
tasks:
- name: Install the provided package
yum: pkg={{ pkgtoinstall }} state=latest
[test@localhost ansible]$
Before Installation -:
[test@localhost opt]$ rpm -qa | grep telnet
[test@localhost opt]$
[test@localhost ansible]$ ansible-playbook prompt.yml
which package need to install?: telnet*
PLAY [target]
***************************************************************************************************************************************************************
TASK [Install the provided package] *****************************************************************************************************************************************
changed: [192.168.56.102]
PLAY RECAP ******************************************************************************************************************************************************************
192.168.56.102 : ok=1 changed=1 unreachable=0 failed=0
[test@localhost ansible]$
After Installation -:
[test@localhost opt]$ rpm -qa | grep telnet
telnet-0.17-64.el7.x86_64
telnet-server-0.17-64.el7.x86_64
[test@localhost opt]$
Now i have removed telnet-server manually and tried to install by giving telnet-*. It is not getting installed.
[test@localhost opt]$ sudo yum remove telnet-server
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package telnet-server.x86_64 1:0.17-64.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================================
Removing:
telnet-server x86_64 1:0.17-64.el7 @base 55 k
Transaction Summary
=============================================================================================================================================================================
Remove 1 Package
Installed size: 55 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : 1:telnet-server-0.17-64.el7.x86_64 1/1
Verifying : 1:telnet-server-0.17-64.el7.x86_64 1/1
Removed:
telnet-server.x86_64 1:0.17-64.el7
Complete!
[test@localhost opt]$ rpm -qa | grep telnet
telnet-0.17-64.el7.x86_64
[test@localhost opt]$
[test@localhost ansible]$ ansible-playbook prompt.yml
which package need to install?: telnet*
PLAY [target] ***************************************************************************************************************************************************************
TASK [Install the provided package] *****************************************************************************************************************************************
ok: [192.168.56.102]
PLAY RECAP ******************************************************************************************************************************************************************
192.168.56.102 : ok=1 changed=0 unreachable=0 failed=0
[test@localhost opt]$ rpm -qa | grep telnet
telnet-0.17-64.el7.x86_64
[test@localhost opt]$
答案 0 :(得分:0)
可能不是您正在寻找的答案,但我明确地安装了2个软件包。使用globs进行包装安装有可能安装你不想要或不需要的东西。
- name: Install the provided package
yum:
pkg: "{{ item }}"
state: latest
with_items:
- telnet
- telnet-server