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

相关推荐
日更嵌入式的打工仔1 分钟前
linux内核查看网口负荷的指令
linux·服务器·笔记
gsls2008082 分钟前
服务器状态监控Uptime Kuma
运维·服务器·git
郝学胜-神的一滴2 分钟前
Linux多线程编程:深入解析pthread_detach函数
linux·服务器·开发语言·c++·程序人生
同聘云4 分钟前
阿里云国际站高防服务器的原理是什么?高防ip怎么做??
服务器·tcp/ip·阿里云
深圳市恒讯科技8 分钟前
美国原生IP服务器有什么优势?
服务器·网络协议·tcp/ip
wdfk_prog9 分钟前
[Linux]学习笔记系列 -- [fs]locks
linux·笔记·学习
HIT_Weston11 分钟前
78、【Ubuntu】【Hugo】搭建私人博客:文章分类
linux·运维·ubuntu
咕噜企业分发小米13 分钟前
阿里云服务器如何实现与其他阿里云产品的无缝集成?
服务器·数据库·阿里云
一个很帅的帅哥16 分钟前
GitHub MCP 服务器(共 58 个,按星标数降序)
服务器·github
哦你看看16 分钟前
Kubernetes 1.28.15 版本网络通信详解
linux