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

相关推荐
!沧海@一粟!2 小时前
麒麟Zabbix Agent安装配置全攻略
linux·服务器·zabbix
似水এ᭄往昔6 小时前
【Linux】自动化构建-make/Makefile
linux·运维·服务器·ubuntu
顶点多余6 小时前
Linux“信号“从硬件到软件详解
linux·运维·服务器
瀚高PG实验室7 小时前
rpm包安装报错:cannot open Packages index using db5 - Cannot allocate memory (12)
linux·运维·服务器·瀚高数据库
追风少年王大爷丶7 小时前
nginx 配置无域名访问拒绝
运维·服务器·nginx
AI+程序员在路上8 小时前
嵌入式软件技术大全
linux·开发语言·arm开发·单片机
black方块cxy8 小时前
实现一个输入框多个ip以逗号分隔最多20组,且ip不能重复
java·服务器·前端
Snasph8 小时前
在Ubuntu上进行端口转发
linux·运维·ubuntu
线束线缆组件品替网8 小时前
Amphenol RJE1Y22A53644401线束详解与替代网络线束选型指南
运维·服务器·网络·智能路由器·电脑·51单片机
TG_yunshuguoji8 小时前
阿里云代理商: 阿里云部署OpenClaw 个性化配置指南 3 大场景模板详解
服务器·阿里云·云计算·openclaw