创建和运行 Ansible 临时命令
作为系统管理员,您需要在受管节点上安装软件。
请按照正文所述,创建一个名为 /home/greg/ansible/adhoc.sh
的 shell 脚本,该脚本将使用 Ansible 临时命令在各个受管节点上安装 yum
存储库:
存储库1:
存储库的名称为 EX294_BASE
描述为 EX294 base software
基础 URL 为 http://content/rhel8.4/x86_64/dvd/BaseOS
GPG 签名检查为 启用状态
GPG 密钥 URL 为
http://content/rhel8.4/x86_64/dvd/RPM-GPG-KEY-redhat-release
存储库为 启用状态
存储库2:
存储库的名称为 EX294_STREAM
描述为 EX294 stream software
基础 URL 为
http://content/rhel8.4/x86_64/dvd/AppStream
GPG 签名检查为 启用状态
GPG 密钥 URL 为
http://content/rhel8.4/x86_64/dvd/RPM-GPG-KEY-redhat-release
存储库为 启用状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| [greg@control ansible]$ ansible-doc -l | grep yum yum Manages packages with the `yum' package manager yum_repository Add or remove YUM repositories [greg@control ansible]$ ansible-doc yum_repository [greg@control ansible]$ vim /home/greg/ansible/adhoc.sh #!/bin/bash ansible all -m yum_repository -a 'name=EX294_BASE description="EX294 base software" baseurl=http://content/rhel8.4/x86_64/dvd/BaseOS gpgcheck=yes gpgkey=http://content/rhel8.4/x86_64/dvd/RPM-GPG-KEY-redhat-release enabled=yes' ansible all -m yum_repository -a 'name=EX294_STREAM description="EX294 stream software" baseurl=http://content/rhel8.4/x86_64/dvd/AppStream gpgcheck=yes gpgkey=http://content/rhel8.4/x86_64/dvd/RPM-GPG-KEY-redhat-release enabled=yes' [greg@control ansible]$ chmod +x /home/greg/ansible/adhoc.sh [greg@control ansible]$ ./adhoc.sh node2 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "repo": "EX294_BASE", "state": "present" } ... [greg@control ansible]$ ansible all -a 'ls -l /etc/yum.repos.d/' node4 | CHANGED | rc=0 >> total 8 -rw-r--r--. 1 root root 187 Jun 12 06:22 EX294_BASE.repo -rw-r--r--. 1 root root 194 Jun 12 06:22 EX294_STREAM.repo ... [greg@control ansible]$ ansible all -m yum -a 'list=repos' node4 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": false, "msg": "", "results": [ { "repoid": "EX294_BASE", "state": "enabled" }, { "repoid": "EX294_STREAM", "state": "enabled" } ] } ...
|