2017-10-10 225 views
0

以下是我正在努力實現的目標。我必須與依賴關係一起安裝一個包。我正在嘗試安裝telnet軟件包。對於這兩個軟件包必須按我的要求進行安裝,這些軟件包是telnet和telnet-server。在某些服務器中,telnet已安裝,但未安裝telnet-server。如果已經安裝了telnet軟件包,那麼如果我在提示中通過telnet- *,則它不會安裝telnet-server。下面是劇本執行如何通過yum安裝子包裝

[[email protected] 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 

[[email protected] ansible]$ 

Before Installation -: 

[[email protected] opt]$ rpm -qa | grep telnet 
[[email protected] opt]$ 

[[email protected] 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 

[[email protected] ansible]$ 

After Installation -: 

[[email protected] opt]$ rpm -qa | grep telnet 
telnet-0.17-64.el7.x86_64 
telnet-server-0.17-64.el7.x86_64 
[[email protected] opt]$ 

Now i have removed telnet-server manually and tried to install by giving telnet-*. It is not getting installed. 

[[email protected] 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! 
[[email protected] opt]$ rpm -qa | grep telnet 
telnet-0.17-64.el7.x86_64 
[[email protected] opt]$ 

[[email protected] 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 

[[email protected] opt]$ rpm -qa | grep telnet 
telnet-0.17-64.el7.x86_64 
[[email protected] opt]$ 

回答

0

大概不會回答你正在尋找,但我會明確地安裝2個包。使用globs進行軟件包安裝有可能安裝您不需要或不需要的東西。

- name: Install the provided package 
    yum: 
    pkg: "{{ item }}" 
    state: latest 
    with_items: 
    - telnet 
    - telnet-server