blockinfile模块:
服务器:[root@server ~]# systemctl stop firewalld
[root@server .ansible]# ansible node -m blockinfile -a "path=/root/ansible_text block='blockinfile insert content'"
[root@server .ansible]# ansible node -m blockinfile -a "path=/root/ansible_text block='blockinfile with mark'" ker=#{mark} test
[root@server .ansible]# ansible node -m blockinfile -a "path=/root/ansible_text block='insertafter'insertafter='blockinfile insert content'"
[root@server .ansible]# ansible node -m blockinfile -a "path=/root/ansible_text block='insertbefore'insertbefore='blockinfile insert content'"
[root@server .ansible]# ansible node -m blockinfile -a "path=/root/ansible_text block="" marker= #{mark} service to start
[root@server .ansible]# ansible node -m blockinfile -a "path=/root/ansible_text block='HELLOW ANSIBLE HIIII'"
[root@server ~]# ansible node -m lineinfile -a "path=/root/ansible_test regexp='(H,{4}).*(H.{4})' line='Hiiii' backrefs=yes"
linefile模块
[root@server ~]# ansible node -m lineinfile -a "path=/root/ansible_test line='lineinfile insert content'"
[root@server ~]# ansible node -m lineinfile -a "path=/root/ansible_test regexp='^lineinfile insert content' state=absent"
[root@server ~]# ansible node -m lineinfile -a "path=/root/ansible_test insertafter='lineinfile insert content'"
[root@server ~]# ansible node -m lineinfile -a "path=/root/ansible_test insertbefore='lineinfile insert content'"
unarchive模块
[root@server ~]# ansible all -m unarchive -a "src=/tmp/foo.zip dest=/data copy=no mode =0644"
archive模块
[root@server ~]# ansible websrvs -m archive -a "path=/var/log/ dest= data/log.tar.bz2 format=bz2 owner=student mode=0777"
cron模块
[root@server ~]# ansible node -m cron -a "hour=9 weekday=1-5 name='student' job=/root/alarm_corn"
user模块
[root@server ~]# python3
Python 3.6.8 (default, Jun 23 2022, 19:01:59)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-13)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import crypt
>>> crypt.crypt("123456")
'$6$gY87RFxBMILVeMDl$QONttsd2UynSPE2FKQhXqGbSkHCtdlH6VJdxymQrKj6DdPaB4Y05Nmdq/6.h1w/d9ByE/HTLCthi8w8l750Tq0'
[root@server ~]# ansible node -m user -a "name=HUYAN passwd='$6$gY87RFxBMILVeMDl$QONttsd2UynSPE2FKQhXqGbSkHCtdlH6VJdxymQrKj6DdPaB4Y05Nmdq/6.h1w/d9ByE/HTLCthi8w8l750Tq0'"
[root@server ~]# ansible node -m user -a "name=HUYAN state=absent remove=yes"
yum_repository
[root@server ~]# ansible node -m yum_repository -a "name=BaseOS baseurl ='file://mnt/my.repo' enable=1 gpgcheck=0 file=redhat description=BaseOS"
service/systemd模块
[root@node2 ~]# ansible all -m systemd -a "name=firewalld state=stoped enabled=yes"
[root@node2 ~]# ansible all -m systemd -a "name=firewalld state=restarted enabled=yes"
[root@node2 ~]# ansible all -m service -a "name=firewalld state=stoped enabled=no"
firewalld模块
[root@server ~]# ansible node -m firewalld -a "prot=22/tcp state=enabled"
[root@server ~]# ansible node -m firewalld -a "service=http state=enabled"
[root@server ~]# ansible node -m firewalld -a "rich_rule='rule family=ipv4 source address=192.168.111.0/24 servicename=http accept' state=enabled"
selinux模块
[root@server ~]# ansible node -m selinux -a "state=permissive"
nmcli模块
[root@server ~]# ansible node -m nmcli -a "con_name=static ifname=ens224 ipv4=192.168.111.150/24 gw4=192.168.111.2 dns4=114.114.114.114 autoconnect=yes type=ethernet state=present "
[root@server ~]# ansible ndoe -m command -a "nmcli c up static"
get_url模块
[root@server ~]# ansible node -m get_url -a "url='https://video.pearvideo.com/mp4/short/20210816/cont-1739036-15747750-hd.mp4' dest=/root/ owner=student group=student mode=0644"
uri模块
[root@server ~]# ansible node -m uri -a "url='https://www.baidu.com' method=get return_content=yes"
parted模块
[root@server ~]# ansible node -m parted -a "device=/dev/nvme0n2 number=1 part_start=1GiB part_end=1GiB state=present"
lvg模块
[root@server ~]# ansible node -m lvg -a "pvs=/dev/nvme0n2p1 ,/dev/nvme0n2p2 pesize=4M vg=myvg"
lvol模块
[root@server ~]# ansible node -m lvol -a "lvs=mylvs vg=myvg size=500M"
filesystem模块
[root@server ~]# ansible node -m filesystem -a "device=/dev/nvme02np2 fstype=ext3"
mount模块
[root@server ~]# ansible node -m mount -a "src=/dev/nvme0n2p3 dest=/ansible_mount state=mounted fstype=xfs"
[root@server ~]# ansible node -m mount -a "src=/dev/nvme0n2p3 dest=/ansible_mount1 state=present fstype=xfs"