文章插图
ansible node1 -m cron -a 'name="shuchu" job="/bin/echo I AM RHCE" user=root minute=0 hour=14 state=present'
案例21:get_url
文章插图
语法:ansible node1 -m get_url -a 'url=需要下载的文件 dest=存放的位置'
部署web服务器[root@ansible ~]# su - studentLast login: Fri Oct 21 11:08:53 CST 2022 on pts/0[student@ansible ~]$ cd ansible/下载本地仓库
[student@ansible ansible]$ ansible node1 -m yum_repository -a 'file=server name=baseos description=centos8 baseurl=file:///mnt/BaseOS enabled=yes gpgcheck=no'node1 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "repo": "baseos", "state": "present"}[student@ansible ansible]$ ansible node1 -m yum_repository -a 'file=server name=appsteram description=centos8 baseurl=file:///mnt/AppStream enabled=yes gpgcheck=no'node1 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "repo": "appsteram", "state": "present"}挂载本地仓库
[student@ansible ansible]$ ansible node1 -m mount -a 'src=https://www.huyubaike.com/dev/cdrom path=/mnt fstype=iso9660 state=mounted'node1 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "dump": "0", "fstab": "/etc/fstab", "fstype": "iso9660", "name": "/mnt", "opts": "defaults", "passno": "0", "src": "/dev/cdrom"}下载htppd
[student@ansible ansible]$ ansible node1 -m yum -a 'name=httpd state=installed'node1 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "msg": "", "rc": 0, "results": [ "Installed: mailcap-2.1.48-3.el8.noarch", "Installed: httpd-2.4.37-30.module_el8.3.0+462+ba287492.0.1.x86_64", "Installed: httpd-filesystem-2.4.37-30.module_el8.3.0+462+ba287492.0.1.noarch", "Installed: apr-1.6.3-11.el8.x86_64", "Installed: httpd-tools-2.4.37-30.module_el8.3.0+462+ba287492.0.1.x86_64", "Installed: centos-logos-httpd-80.5-2.el8.noarch", "Installed: mod_http2-1.15.7-2.module_el8.3.0+477+498bb568.x86_64", "Installed: apr-util-1.6.1-6.el8.x86_64", "Installed: apr-util-bdb-1.6.1-6.el8.x86_64", "Installed: apr-util-openssl-1.6.1-6.el8.x86_64" ]}做软链接
[student@ansible ansible]$ ansible node1 -m file -a 'src=https://www.huyubaike.com/var/www/html dest=/www state=link'node1 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "dest": "/www", "gid": 0, "group": "root", "mode": "0777", "owner": "root", "size": 13, "src": "/var/www/html", "state": "link", "uid": 0}node1中查看[root@node1 /]# ll -d /wwwlrwxrwxrwx 1 root root 13 Oct 24 15:58 /www -> /var/www/html输入内容
[student@ansible ansible]$ ansible node1 -m shell -a 'echo "my name is luojialong" > /www/index.html'node1 | CHANGED | rc=0 >>[student@ansible ansible]$ ansible node1 -m shell -a 'cat /www/index.html'node1 | CHANGED | rc=0 >>my name is luojialong
推荐阅读
- 这才是使用ps命令的正确姿势
- Ansible 批处理实战
- 小米手环6nfc使用体验_小米手环6nfc使用测评
- CF中怎么改名(cf买了改名卡怎么使用)
- 使用LEFT JOIN 统计左右存在的数据
- ansible应用之安装elk框架
- 使用 etcdadm 快速、弹性部署 etcd 集群
- Android RecyclerView使用ListAdapter高效刷新数据
- 使用 Windows Core Audio APs 进行 Loopback Recording 并生成 WAV 文件
- 4 .NET 6学习笔记——如何在.NET 6的Desktop App中使用Windows Runtime API