RHCE8 练习题:创建和运行Ansible临时命令

作为系统管理员,您需要在受管节点上安装软件。 赵正文所述,创建一个名为/home/student/ansible/adhoc.sh的shell脚本,该脚本将使用ansible零食命令在各个受管节点上安装yum存储库。

  1. 储存库1
  2. 储存库2

查找模块及模块详细信息

ansible-doc -l | grep xxx
ansible-doc xxx
ansible 主机或主机组 -m  模块名 -a 命令或命令组

Answer:

cd ~/ansible
vim adhoc.sh ####符号中为文件内容
#!/bin/bash
ansible all \
    -m yum_repository \
    -a 'name="EX294_BASE" \
        description="EX294 base softeware" \
        baseurl="http://content.example.com/rhel8.0/x86_64/dvd/BaseOS" \
        enabled=yes \
        gpgcheck=yes \
        gpgkey="http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release"'
ansible all \
    -m yum_repository \
    -a 'name="EX294_STREAM" \
        description="EX294 stream software" \
        baseurl="http://content.example.com/rhel8.0/x86_64/dvd/AppStream" \
        enabled=yes \
        gpgcheck=yes \
        gpgkey="http://content.example.com/rhel8.0/x86_64/dvd/RPM-GPG-KEY-redhat-release"'
bash adhoc.sh

验证

ansible all -a 'yum repolist'
ansible test -m shell -a 'yum list|wc -l'

file