当前位置:   article > 正文

Linux之ansible模块使用大全(blockinfile,lineinfile,unarchive,archive,cron,user,group,yum_repository等)_ansible 写入内容

ansible 写入内容

目录

1.blockinfile模块使用:在rhce上文件ansible.txt文件中写入内容 ansible

​然后使用blockinfile模块,在文件中插入内容 blockinfile insert content

然后插入内容 blockinfile with marker 且使用指定标记: marker=#{mark}test

在blockinfile insert content之前插入 insertbefore

在blockinfile insert content之后插入 insertafter

删除其中一行内容

2.lineinfile模块使用向node节点上文件 ansible.txt2文件如插入内容 lineinfile insert content

删除lineinfile insert content

重新插入lineinfile insert content 

在之前插入: insertbefore

在它之后插入: insertafter

插入:Hello ansible,Hiiii

文件中的"Hello ansible,Hiiii"替换成"Hiiii"(使用正则表达式和backrefs)

3.unarchive模块使用将node主机上的包解压

​将server主机上的包解压到node主机且设置权限为644

4.archive模块使用将node上的目录进行压缩

​5.cron模块在node上为student用户设置周一到周五早上的9:00输出闹钟到/root/alarm_cron

6.user模块创建用户

删除用户

7.group模块创建组

删除组

8.yum_repository设置两个软件仓库BaseOS和APPStream(本地yum源的配置)到文件my.repo

9.yum/dnf模块安装软件 lrzsz

10.service/systemd模块关闭防火墙

​重启防火墙

​禁用防火墙

​11.firewalld模块添加端口22, 添加服务 http

添加富规则:允许192.168.xxx.0/24来访问http的80端口

删除富规则

12.selinux模块设置selinux工作模式为permissive

13.nmcli模块在node上添加一块网卡,设置IP,gw, method, dns,type,和自动连接

14.get_url模块去梨视频找个视频下载下来

15.uri模块访问百度,并能获取到百度源码

16.parted模块新增一块儿1GB的磁盘

​然后对磁盘进行分区:  分区1: 400,分区2: 200M, 分区3:200M,且设置分区1和分区2类型为LVM  

​17.lvg模块:用上面parted建立的分区: 创建卷组

18.lvol模块:在上面卷组的基础上创建逻辑卷:500M

19.filesystem模块:为逻辑卷和分区3设置文件系统类型为 xfs

20.mount模块:为上面的逻辑卷和分区3进行挂载(分别使用mounted和present)


1.blockinfile模块使用:
在rhce上文件ansible.txt文件中写入内容 ansible


然后使用blockinfile模块,在文件中插入内容 blockinfile insert content

  1. [root@rhcsa ~]# ansible rhce -m blockinfile -a "path=/root/ansible.txt block='blockinfile insert content' insertafter=EOF"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "msg": "Block inserted"
  8. }

然后插入内容 blockinfile with marker 且使用指定标记: marker=#{mark}test

  1. [root@rhcsa ~]# ansible rhce -m blockinfile -a "path=/root/ansible.txt block='blockinfile with marker' marker=#{mark}test"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "msg": "Block inserted"
  8. }

在blockinfile insert content之前插入 insertbefore

  1. [root@rhcsa ~]# ansible rhce -m blockinfile -a "path=/root/ansible.txt block='insertbefore' insertbefore='blockinfile insert content' marker='#{mark} test'"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "msg": "Block inserted"
  8. }

在blockinfile insert content之后插入 insertafter

  1. [root@rhcsa ~]# ansible rhce -m blockinfile -a "path=/root/ansible.txt block='insertafter' insertafter='blockinfile insert content' marker='#{mark} test1'"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "msg": "Block inserted"
  8. }

删除其中一行内容

  1. [root@rhcsa ~]# ansible rhce -m blockinfile -a "path=/root/ansible.txt block='insertafyer' insertafter='blockinfile insert content' marker='#{mark} test1' state=absent"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "msg": "Block removed"
  8. }

2.lineinfile模块使用
向node节点上文件 ansible.txt2文件如插入内容 lineinfile insert content

  1. [root@rhcsa ~]# ansible rhce -m lineinfile -a "path=/root/ansible.txt2 line='lineinfile insert content' create=yes"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "backup": "",
  7. "changed": true,
  8. "msg": "line added"
  9. }

删除lineinfile insert content

  1. [root@rhcsa ~]# ansible rhce -m lineinfile -a "path=/root/ansible.txt2 line='lineinfile insert content' state=absent"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "backup": "",
  7. "changed": true,
  8. "found": 1,
  9. "msg": "1 line(s) removed"
  10. }

重新插入lineinfile insert content 

在之前插入: insertbefore

  1. [root@rhcsa ~]# ansible rhce -m lineinfile -a "path=/root/ansible.txt2 line='insertbefore' insertbefore='lineinfile insert content'"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "backup": "",
  7. "changed": true,
  8. "msg": "line added"
  9. }

在它之后插入: insertafter

  1. [root@rhcsa ~]# ansible rhce -m lineinfile -a "path=/root/ansible.txt2 line='insertafter' insertafter='lineinfile insert content'"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "backup": "",
  7. "changed": true,
  8. "msg": "line added"
  9. }

插入:Hello ansible,Hiiii

  1. [root@rhcsa ~]# ansible rhce -m lineinfile -a "path=/root/ansible.txt2 line='Hello ansible,Hiiii'"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "backup": "",
  7. "changed": true,
  8. "msg": "line added"
  9. }

文件中的"Hello ansible,Hiiii"替换成"Hiiii"(使用正则表达式和backrefs)

  1. [root@rhcsa ~]# ansible rhce -m lineinfile -a "path=/root/ansible.txt2 regexp='(H.{4}).*(H.{4})' line='Hiiii'"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "backup": "",
  7. "changed": true,
  8. "msg": "line replaced"
  9. }

3.unarchive模块使用
将node主机上的包解压


将server主机上的包解压到node主机且设置权限为644

  1. [root@rhcsa ~]# ansible rhce -m unarchive -a "src=/root/apr-1.6.5.tar.gz dest=/home/student mode=0644"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "dest": "/home/student",
  8. "extract_results": {
  9. "cmd": [
  10. "/bin/gtar",
  11. "--extract",
  12. "-C",
  13. "/home/student",
  14. "-z",
  15. "-f",
  16. "/home/student/.ansible/tmp/ansible-tmp-1659695531.3050132-5926-83183719667943/source"
  17. ],
  18. "err": "",
  19. "out": "",
  20. "rc": 0
  21. },
  22. "gid": 1112,
  23. "group": "student",
  24. "handler": "TgzArchive",
  25. "mode": "0664",
  26. "owner": "student",
  27. "secontext": "unconfined_u:object_r:user_home_dir_t:s0",
  28. "size": 270,
  29. "src": "/home/student/.ansible/tmp/ansible-tmp-1659695531.3050132-5926-83183719667943/source",
  30. "state": "directory",
  31. "uid": 1112
  32. }

4.archive模块使用
将node上的目录进行压缩


5.cron模块
在node上为student用户设置周一到周五早上的9:00输出闹钟到/root/alarm_cron

  1. [root@rhcsa ~]# ansible rhce -m cron -a "hour=9 minute=0 weekday=1-5 name="闹钟" job=/root/alarm_cron user=student"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "envs": [],
  8. "jobs": [
  9. "闹钟"
  10. ]
  11. }

6.user模块
创建用户

  1. [root@rhcsa ~]# ansible rhce -m user -a "name=li"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "comment": "",
  8. "create_home": true,
  9. "group": 1113,
  10. "home": "/home/li",
  11. "name": "li",
  12. "shell": "/bin/bash",
  13. "state": "present",
  14. "system": false,
  15. "uid": 1113
  16. }

删除用户

  1. [root@rhcsa ~]# ansible rhce -m user -a "name=li state=absent"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "force": false,
  8. "name": "li",
  9. "remove": false,
  10. "state": "absent"
  11. }

7.group模块
创建组

  1. [root@rhcsa ~]# ansible rhce -m group -a "name=li"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "gid": 1113,
  8. "name": "li",
  9. "state": "present",
  10. "system": false
  11. }

删除组

  1. [root@rhcsa ~]# ansible rhce -m group -a "name=li state=absent"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "name": "li",
  8. "state": "absent"
  9. }

8.yum_repository
设置两个软件仓库BaseOS和APPStream(本地yum源的配置)到文件my.repo

  1. [root@rhcsa ~]# ansible rhce -m yum_repository -a "name=BaseOS baseurl=file:///mnt/cdrom/BaseOS gpgcheck=0 enabled=1 file=my.repo description=BaseOS"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "repo": "BaseOS",
  8. "state": "present"
  9. }
  1. [root@rhcsa ~]# ansible rhce -m yum_repository -a "name=APPStream baseurl=file:///mnt/cdrom/AppStream gpgcheck=0 enabled=1 file=my.repo description=APPStream"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "repo": "APPStream",
  8. "state": "present"
  9. }

9.yum/dnf模块
安装软件 lrzsz

  1. [root@rhcsa ~]# ansible rhce -m yum -a "name=lrzsz"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "msg": "",
  8. "rc": 0,
  9. "results": [
  10. "Installed: lrzsz-0.12.20-43.el8.x86_64"
  11. ]
  12. }

10.service/systemd模块
关闭防火墙


重启防火墙


禁用防火墙


11.firewalld模块
添加端口22, 添加服务 http

  1. rhce | SUCCESS => {
  2. "ansible_facts": {
  3. "discovered_interpreter_python": "/usr/libexec/platform-python"
  4. },
  5. "changed": false,
  6. "msg": "Permanent and Non-Permanent(immediate) operation"
  7. }
  8. [root@rhcsa ~]# ansible rhce -m firewalld -a 'port=22/tcp permanent=true immediate=true state=enabled'
  9. rhce | CHANGED => {
  10. "ansible_facts": {
  11. "discovered_interpreter_python": "/usr/libexec/platform-python"
  12. },
  13. "changed": true,
  14. "msg": "Permanent and Non-Permanent(immediate) operation, Changed port 22/tcp to enabled"
  15. }

添加富规则:允许192.168.xxx.0/24来访问http的80端口

  1. [root@rhcsa ~]# ansible rhce -m firewalld -a 'rich_rule="rule family=ipv4 source address=192.168.40.0/24 service name=http accept" permanent=true immediate=true state=enabled'
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "msg": "Permanent and Non-Permanent(immediate) operation, Changed rich_rule rule family=ipv4 source address=192.168.40.0/24 service name=http accept to enabled"
  8. }

删除富规则

  1. [root@rhcsa ~]# ansible rhce -m firewalld -a 'rich_rule="rule family=ipv4 source address=192.168.40.0/24 service name=http accept" state=disabled'
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "msg": "Non-permanent operation, Changed rich_rule rule family=ipv4 source address=192.168.40.0/24 service name=http accept to disabled"
  8. }

12.selinux模块
设置selinux工作模式为permissive

  1. [root@rhcsa ~]# ansible rhce -m selinux -a "state=permissive policy=targeted"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "configfile": "/etc/selinux/config",
  8. "msg": "SELinux state changed from 'enforcing' to 'permissive', Config SELinux state changed from 'enforcing' to 'permissive'",
  9. "policy": "targeted",
  10. "reboot_required": false,
  11. "state": "permissive"
  12. }

13.nmcli模块
在node上添加一块网卡,设置IP,gw, method, dns,type,和自动连接

  1. [root@rhcsa ~]# ansible rhce -m nmcli -a "conn_name=ens666 ip4=192.168.40.140/24 gw4=192.168.40.1 dns4=114.114.114.114 type=ethernet state=present"
  2. rhce | CHANGED => {
  3. "Exists": "Connections do exist so we are modifying them",
  4. "ansible_facts": {
  5. "discovered_interpreter_python": "/usr/libexec/platform-python"
  6. },
  7. "changed": true,
  8. "conn_name": "ens666",
  9. "state": "present"
  10. }

14.get_url模块
去梨视频找个视频下载下来

  1. [root@rhcsa ~]# ansible rhce -m get_url -a "url=https://video.pearvideo.com/mp4/adshort/20180504/cont-1337568-12007359_adpkg-ad_hd.mp4 dest=/root"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "checksum_dest": null,
  8. "checksum_src": "c8c67c158b16ce84172273cc14dcc1c9f9403ef8",
  9. "dest": "/root/cont-1337568-12007359_adpkg-ad_hd.mp4",
  10. "elapsed": 7,
  11. "gid": 0,
  12. "group": "root",
  13. "md5sum": "dee2f423b48d0ce9d6e8ca6f6e78e443",
  14. "mode": "0644",
  15. "msg": "OK (11510845 bytes)",
  16. "owner": "root",
  17. "secontext": "system_u:object_r:admin_home_t:s0",
  18. "size": 11510845,
  19. "src": "/home/student/.ansible/tmp/ansible-tmp-1659700195.5528436-7695-163031912329044/tmpmcmvn8m5",
  20. "state": "file",
  21. "status_code": 200,
  22. "uid": 0,
  23. "url": "https://video.pearvideo.com/mp4/adshort/20180504/cont-1337568-12007359_adpkg-ad_hd.mp4"
  24. }

15.uri模块
访问百度,并能获取到百度源码

  1. [root@rhcsa ~]# ansible rhce -m uri -a "url=https://www.baidu.com"
  2. rhce | SUCCESS => {
  3. "accept_ranges": "bytes",
  4. "ansible_facts": {
  5. "discovered_interpreter_python": "/usr/libexec/platform-python"
  6. },
  7. "cache_control": "no-cache",
  8. "changed": false,
  9. "connection": "close",
  10. "content_length": "227",
  11. "content_type": "text/html",
  12. "cookies": {
  13. "BAIDUID": "DF867D0B7155041007B51368264CE9AB:FG=1",
  14. "BD_NOT_HTTPS": "1",
  15. "BIDUPSID": "DF867D0B715504104B9BE896590DAD78",
  16. "PSTM": "1659700306"
  17. },
  18. "cookies_string": "BAIDUID=DF867D0B7155041007B51368264CE9AB:FG=1; BIDUPSID=DF867D0B715504104B9BE896590DAD78; PSTM=1659700306; BD_NOT_HTTPS=1",
  19. "date": "Fri, 05 Aug 2022 11:51:46 GMT",
  20. "elapsed": 0,
  21. "msg": "OK (227 bytes)",
  22. "p3p": "CP=\" OTI DSP COR IVA OUR IND COM \", CP=\" OTI DSP COR IVA OUR IND COM \"",
  23. "pragma": "no-cache",
  24. "redirected": false,
  25. "server": "BWS/1.1",
  26. "set_cookie": "BD_NOT_HTTPS=1; path=/; Max-Age=300, BIDUPSID=DF867D0B715504104B9BE896590DAD78; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com, PSTM=1659700306; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com, BAIDUID=DF867D0B7155041007B51368264CE9AB:FG=1; max-age=31536000; expires=Sat, 05-Aug-23 11:51:46 GMT; domain=.baidu.com; path=/; version=1; comment=bd",
  27. "status": 200,
  28. "strict_transport_security": "max-age=0",
  29. "traceid": "1659700306025489869811720199910870649460",
  30. "url": "https://www.baidu.com",
  31. "x_frame_options": "sameorigin",
  32. "x_ua_compatible": "IE=Edge,chrome=1"
  33. }

16.parted模块
新增一块儿1GB的磁盘


然后对磁盘进行分区:  分区1: 400,分区2: 200M, 分区3:200M,且设置分区1和分区2类型为LVM  

  1. [root@rhcsa ~]# ansible rhce -m parted -a "device=/dev/nvme0n3 number=1 part_end=400MB state=present flags=lvm"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "disk": {
  8. "dev": "/dev/nvme0n3",
  9. "logical_block": 512,
  10. "model": "NVMe Device",
  11. "physical_block": 512,
  12. "size": 1048576.0,
  13. "table": "msdos",
  14. "unit": "kib"
  15. },
  16. "partitions": [
  17. {
  18. "begin": 1024.0,
  19. "end": 390144.0,
  20. "flags": [
  21. "lvm"
  22. ],
  23. "fstype": "",
  24. "name": "",
  25. "num": 1,
  26. "size": 389120.0,
  27. "unit": "kib"
  28. }
  29. ],
  30. "script": "unit KiB mklabel msdos mkpart primary 0% 400MB unit KiB set 1 lvm on"
  31. }
  1. [root@rhcsa ~]# ansible rhce -m parted -a "device=/dev/nvme0n3 number=2 part_start=400MB part_end=600MB state=present flags=lvm"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "disk": {
  8. "dev": "/dev/nvme0n3",
  9. "logical_block": 512,
  10. "model": "NVMe Device",
  11. "physical_block": 512,
  12. "size": 1048576.0,
  13. "table": "msdos",
  14. "unit": "kib"
  15. },
  16. "partitions": [
  17. {
  18. "begin": 1024.0,
  19. "end": 390144.0,
  20. "flags": [
  21. "lvm"
  22. ],
  23. "fstype": "",
  24. "name": "",
  25. "num": 1,
  26. "size": 389120.0,
  27. "unit": "kib"
  28. },
  29. {
  30. "begin": 390144.0,
  31. "end": 585728.0,
  32. "flags": [
  33. "lvm"
  34. ],
  35. "fstype": "",
  36. "name": "",
  37. "num": 2,
  38. "size": 195584.0,
  39. "unit": "kib"
  40. }
  41. ],
  42. "script": "unit KiB mkpart primary 400MB 600MB unit KiB set 2 lvm on"
  43. }
  1. [root@rhcsa ~]# ansible rhce -m parted -a "device=/dev/nvme0n3 number=3 part_start=600MB part_end=800MB state=present"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "disk": {
  8. "dev": "/dev/nvme0n3",
  9. "logical_block": 512,
  10. "model": "NVMe Device",
  11. "physical_block": 512,
  12. "size": 1048576.0,
  13. "table": "msdos",
  14. "unit": "kib"
  15. },
  16. "partitions": [
  17. {
  18. "begin": 1024.0,
  19. "end": 390144.0,
  20. "flags": [
  21. "lvm"
  22. ],
  23. "fstype": "",
  24. "name": "",
  25. "num": 1,
  26. "size": 389120.0,
  27. "unit": "kib"
  28. },
  29. {
  30. "begin": 390144.0,
  31. "end": 585728.0,
  32. "flags": [
  33. "lvm"
  34. ],
  35. "fstype": "",
  36. "name": "",
  37. "num": 2,
  38. "size": 195584.0,
  39. "unit": "kib"
  40. },
  41. {
  42. "begin": 585728.0,
  43. "end": 781312.0,
  44. "flags": [],
  45. "fstype": "",
  46. "name": "",
  47. "num": 3,
  48. "size": 195584.0,
  49. "unit": "kib"
  50. }
  51. ],
  52. "script": "unit KiB mkpart primary 600MB 800MB"
  53. }

 17.lvg模块:用上面parted建立的分区: 创建卷组

  1. [root@rhcsa ~]# ansible rhce -m lvg -a 'pvs=/dev/nvme0n3p1 vg=myvg1'
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true
  7. }

18.lvol模块:在上面卷组的基础上创建逻辑卷:500M

  1. [root@rhcsa ~]# ansible rhce -m lvol -a 'vg=myvg1 lv=lv1 size=500'
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true,
  7. "msg": ""
  8. }

19.filesystem模块:为逻辑卷和分区3设置文件系统类型为 xfs

  1. [root@rhcsa ~]# ansible rhce -m filesystem -a 'dev=/dev/myvg1/lv1 fstype=xfs force=yes'
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true
  7. }
  1. [root@rhcsa ~]# ansible rhce -m filesystem -a 'dev=/dev/nvme0n3p3 fstype=xfs force=yes'
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "changed": true
  7. }

20.mount模块:
为上面的逻辑卷和分区3进行挂载(分别使用mounted和present)

  1. [root@rhcsa ~]# ansible rhce -m mount -a "path=/mnt/test fstype=xfs src=/dev/myvg1 state=present"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "backup_file": "",
  7. "boot": "yes",
  8. "changed": true,
  9. "dump": "0",
  10. "fstab": "/etc/fstab",
  11. "fstype": "xfs",
  12. "name": "/mnt/test",
  13. "opts": "defaults",
  14. "passno": "0",
  15. "src": "/dev/myvg1"
  16. }
  1. [root@rhcsa ~]# ansible rhce -m mount -a "path=/mnt/test1 fstype=xfs src=/dev/nvme0n3p3 state=present"
  2. rhce | CHANGED => {
  3. "ansible_facts": {
  4. "discovered_interpreter_python": "/usr/libexec/platform-python"
  5. },
  6. "backup_file": "",
  7. "boot": "yes",
  8. "changed": true,
  9. "dump": "0",
  10. "fstab": "/etc/fstab",
  11. "fstype": "xfs",
  12. "name": "/mnt/test1",
  13. "opts": "defaults",
  14. "passno": "0",
  15. "src": "/dev/nvme0n3p3"
  16. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/837438
推荐阅读
  

闽ICP备14008679号