ansible 例子

ansible all -i inventory --list-hosts

ansible web -i inventory --list-hosts

ssh-keygen

ssh-copy-id

ansible localhost -m ping

ansible localhost -m command -a "hostname"

ansible localhost -m command -a "hostname" -o

ansible localhost -m shell -a "set" -o

ansible-doc -l | grep temp

ansible-doc template

ansible localhost -m template -a "src=/root/aa1.txt dest=/root/aa2.txt"

yum

yum模块用于在指定节点机器上通过yum管理软件,其支持的参数主要有两个

name:要管理的包名

state:要进行的操作

state常用的值:

latest:安装软件

installed:安装软件

present:安装软件

removed:卸载软件

absent:卸载软件

ansible localhost -m yum -a "name=vsftpd state=present"

ansible localhost -m copy -a "src=/root/aa2.txt dest=/root/aa3.txt"

ansible localhost -m user -a "name=testuser group=test"

ansible localhost -m user -a "name=testuser state=absent remove=yes"

ansible localhost -m service -a "name=vsftpd state=started"

ansible localhost -m service -a "name=vsftpd state=stopped"

ansible localhost -m file -a "path=/root/aa1.txt state=absent"

  • name: enable vsftpd and start it

hosts: localhost

tasks:

  • name: enable vsftpd

service:

name: vsftpd

enabled: true

  • name: start vsftpd

service:

name: vsftpd

state: started

  • name: print facts

hosts: localhost

tasks:

  • name: de

debug:

var: ansible_facts["interfaces"]

  • name: test loop

hosts: localhost

vars:

myitem:

  • test1

  • test2

tasks:

  • name: print item

shell: "echo myitem:{{item}}"

loop: "{{myitem}}"

register: result

  • name: debug echo

debug:

var: result

相关推荐
Exquisite.10 分钟前
k8s的Pod管理
linux·运维·服务器
IMPYLH11 分钟前
Linux 的 env 命令
linux·运维·服务器·数据库
桌面运维家13 分钟前
Nginx服务器安全:高级访问控制与流量清洗实战
服务器·nginx·安全
抠脚学代码13 分钟前
Linux开发--> UBoot学习
linux·学习·uboot
奇妙之二进制21 分钟前
后端常见分层模型
linux·服务器
拾贰_C28 分钟前
【Ubuntu | Nvidia 】nvidia 驱动安装
linux·运维·ubuntu
zzzsde38 分钟前
【Linux】EXT文件系统(2)
linux·运维·服务器
艾莉丝努力练剑39 分钟前
【QT】QT快捷键整理
linux·运维·服务器·开发语言·图像处理·人工智能·qt
硅基导游40 分钟前
bpf监控某个应用里各线程锁的申请得到及释放时间
服务器·互斥锁·性能监控
IMPYLH42 分钟前
Linux 的 expand 命令
linux·运维·服务器