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

相关推荐
IMPYLH3 分钟前
Linux 的 stdbuf 命令
linux·运维·服务器·bash
郝学胜-神的一滴5 分钟前
从底层看透Linux高性能服务器:epoll自定义封装与超时清理实战
linux·服务器·c++·网络协议·tcp/ip·unix
keyipatience10 分钟前
12.GDB调试技巧与计算机体系结构解析
linux·运维·服务器
小夏子_riotous11 分钟前
Docker学习路径——9、Docker 网络深度解析:从默认网络到自定义网络实战
linux·运维·网络·docker·容器·centos·云计算
峥无15 分钟前
《read/write的秘密:文件描述符、重定向与用户态缓冲区》
linux·运维·服务器·进程
fish_xk22 分钟前
Linux操作系统
linux
zh路西法24 分钟前
【udev重命名详细教程】放弃硬编码,从重命名开始
linux·机器人
studytosky34 分钟前
【高并发内存池】线程缓存核心原理与实现
linux·服务器·git·缓存
lihao lihao35 分钟前
Linux文件与fd
java·linux·算法
奇妙之二进制1 小时前
fastdds源码分析之EDP协议
运维·服务器·网络