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

相关推荐
习惯就好zz42 分钟前
WSL2 安装Ubuntu卡在安装进度0%无响应问题解决
linux·windows·ubuntu·wsl·wsl2
躲猫猫的喵喵2 小时前
Ubuntu2204降内核版本
linux·运维·服务器·ubuntu
昌sit!2 小时前
Linux系统性基础学习笔记
linux·笔记·学习
zdslovezy2 小时前
CentOS 系统升级 OpenSSH 和 OpenSSL 的完整方案
linux·运维·centos
HIT_Weston3 小时前
18、【Ubuntu】【远程开发】技术方案分析:私网ip掩码
linux·tcp/ip·ubuntu
cccccc语言我来了3 小时前
(Linux (6):从包管理到工具探索,构建系统操作基础认知)
linux·运维·服务器
ben9518chen4 小时前
嵌入式Linux C语言程序设计九
linux·c语言
wuk9984 小时前
CentOS7环境搭建L2TP服务器
运维·服务器
恒创科技HK4 小时前
香港1核2G云服务器当网站服务器够用不?
运维·服务器
颜大哦5 小时前
linux安装mysql
linux·运维·mysql·adb