ansible使用临时命令通过模块来执行任务( 三 )


ansible使用临时命令通过模块来执行任务

文章插图
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使用临时命令通过模块来执行任务

文章插图
语法: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

推荐阅读