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

相关推荐
Skilce几秒前
K8S部署
linux·运维·服务器·容器·kubernetes
灰暗世界%7 分钟前
飞牛nas如何设置阿里云的DDNS
服务器·网络·阿里云
不爱吃糖的程序媛8 分钟前
鸿蒙三方库适配读懂 `HPKBUILD`:lycium 怎么知道「下载谁、怎么编、装到哪」?
服务器·华为·harmonyos
d1z88811 分钟前
(十七)32天GPU测试从入门到精通-vLLM 部署与性能测试day15
服务器·显卡·nvidia·vllm
重生的黑客13 分钟前
Linux :vim 深入与 gcc 编译详解
linux·运维·vim
屈九歌13 分钟前
【Linux】V4L2框架分析《四》media_controller
linux
小成2023032026515 分钟前
Linux高级03
linux·开发语言
南境十里·墨染春水37 分钟前
linux学习进展 进程
linux·运维·学习
cyber_两只龙宝41 分钟前
【Oracle】Oracle之DQL中SELECT的基础使用
linux·运维·服务器·数据库·云原生·oracle
云栖梦泽42 分钟前
Linux内核与驱动:10.平台总线platform
linux