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

相关推荐
人工智能训练师18 分钟前
Ubuntu22.04如何安装新版本的Node.js和npm
linux·运维·前端·人工智能·ubuntu·npm·node.js
灿烂阳光g22 分钟前
domain_auto_trans,source_domain,untrusted_app
android·linux
Tisfy2 小时前
服务器 - 从一台服务器切换至另一台服务器(损失数十条访客记录)
运维·服务器
Ronin3052 小时前
【Linux系统】日志与策略模式
linux·策略模式·日志
猎板PCB黄浩3 小时前
从废料到碳减排:猎板 PCB 埋容埋阻的绿色制造革命,如何实现环保与性能双赢
java·服务器·制造
ZzzK,3 小时前
JAVA虚拟机(JVM)
java·linux·jvm
Aspiresky4 小时前
浅析Linux进程信号处理机制:基本原理及应用
linux·运维·信号处理
ajassi20004 小时前
linux C 语言开发 (八) 进程基础
linux·运维·服务器
..过云雨5 小时前
05.【Linux系统编程】进程(冯诺依曼体系结构、进程概念、进程状态(注意僵尸和孤儿)、进程优先级、进程切换和调度)
linux·笔记·学习
matlab的学徒5 小时前
Web与Nginx网站服务(改)
linux·运维·前端·nginx·tomcat