ansible setup,
参数描述-a arguments ,-args= arguments 命令行参数-mname,-mNAME,—module-name=NAME=执行模块的名称。默认情况下使用命令模块,因此如果只执行一个命令,可以省略-m参数-i路径。—inventory=PATH指定清单主机文件的路径,默认为/etc/ansible/hosts。-u用户名,—用户=用户名。使用此远程用户名而不是当前用户-U-sud-User=SUDO _用户sudo to哪个用户,默认登录密码是root-k-ask-pass,提示输入SSH密码而不是采用基于密钥的身份验证-k-ask-s-sudo-pass提示密码使用sudo-sudo-S-sudo运行-S-su使用su命令-l-l-list显示所有支持的模块-S-S-snippet指定显示脚本片段的模块-f-f-forks=NUM并行任务数。NUM被指定为整数,默认值为5。# ansi ble testhosts-a "/sbin/reboot "-f 10重新启动test hosts组中的所有计算机,一次10台-PRIVATE-KEY=PRIVATE _ KEY _ FILE私钥路径,使用此文件验证连接-v-v-verbose详细信息allExecute-m module _ path对于hosts定义的所有主机,-module-path=要执行的模块的module _ path路径,默认情况下,/usr/share/ansi ble/-list-hosts仅打印哪些主机将执行此剧本文件,而不是实际执行剧本文件-o尝试在一行中输出所有内容。-t Directory,—tree=Directory将内容保存在此输出目录中,结果保存在每个主机上的一个文件中。-B后台运行超时-P调查后台时间-t秒,-超时=秒时间,单位秒s-p num,-poll=每隔几秒调查后台工作数。-b-c连接是必需的,-connection=使用连接类型。可能的选项有paramiko(SSH)、SSH和local。主要在本地用于crontab或startup。—tags=TAGS只执行指定标签的任务示例:ansi ble-playbook test . ymlTAGS=copy只执行标签为copy的任务—list-tasks列出所有要执行的任务—c、—check只测试会改变的,不会真正执行;相反,尝试预测一些可能的变化——语法—检查语法检查的脚本,但不要执行它—l SUBSET,—limit=SUBSET以进一步限制选定的主机/组模式——limit=192 . 168 . 0 . 15仅针对此ip —skip-tags=SKIP_TAGS仅运行其戏剧和任务与这些值不匹配的标签—SKIP-TAGS=copy _ start-eextra _ vars,—extra-vars=EXTRA_VARS额外变量设置为key=value或YAML/JSON-l—limit192.168.0.11仅针对这两个IPs执行任务多台服务器的清单文件vim/etc/ansible/hosts #应用服务器[app] 192.168.60.4192.168.60.5 #数据库服务器[db]192.168.60.6#组“multi”与所有服务器[multi:children]appdb#将应用于所有服务器的变量[multi:vars]ansi ble _ ssh _ user=vang ansi ble _ ssh _ ssh第一个模块将我们的两个应用服务器放入一个“app”组。
2.第二个块将数据库服务器放入“db”组。
3.第三个块告诉ansible定义一个新组“multi ”,带有子组,我们添加了“app”和“db”组。
4.第四个块向multi组添加变量,这些变量将应用于multi及其所有子组中的所有服务器
ansi ble multi-a hostname ansi ble multi-a hostname -f1这一次是只是用了一个线程服务器有可供我们的应用程序使用的磁盘空间:可变多a df -h 确保我们的服务器上有足够的内存ansi ble multi-a free-m Make changes using Ansible modulesansi ble multi-s-m yum-a name=NTP state=present -s的意思是sudo nsible multi-s-m service-a name=ntpd state=started enabled=yes ansi ble multi-s-a service ntpd stop ansi ble multi-s-a ntpdate-q 0。rhel。游泳池。NTP。org ansi ble multi-s-a service ntpd start Configure groups of servers, or individual serversansi ble app-s-m yum-a name=MySQL-python state=present ansi ble app-s-m yum-a name=python-setup tools state=print django。get _ version() Configure the Database serversansi ble d b-s-m yum-A name=Maria d b-s-m server state=present ansi ble d b-s-m service-A name=Maria db state=started enabled=yes ansi ble d b-s-A iptables-F ansi ble d b-s-A iptables-A INPUT-s 192 .168 .60 .0/24-p TCP \
-m TCP-d端口3306 -j接受
ansi ble d b-s-m yum-a name=MySQL-python state=present ansi ble d b-s-m MySQL _ user-a name=django host=% password=12345 \
priv=* .*:所有状态=存在
Make changes to just one serveransi ble app-s-a 服务协议守护进程状态 ansi ble app-s-a 服务协议守护进程重新启动-极限 192。168 .60 .4 limit后还可以用正则比如--limit "*.4" --limit ~".*\.4"Manage users and groupsansi ble app-s-m group-a name=admin state=present ansi ble app-s-m user-a name=John doe group=admin create home=yes $ ansi ble app-s-m src=/etc/hosts dest=/tmp 远程服务器拉取文件至本机,只能取得文件,不能取得目录,如果拉目录,先焦油/zip再拉到本机即可创建目录和文件ansi ble multi-m file-a dest=/tmp/test mode=644 state=directory ansi ble multi-m file-a src=/src/symlink dest=/dest/symlink \
所有者=根组=根状态=链接
删除目录和文件ansi ble multi-m file-a dest=/tmp/test state=absent Manage files and directoriesansi ble multi-s-B 3600-a yum-y update ansi ble multi-s-m async _ status-a jid=763350539037 使用ansi ble的
异步状态模块
一劳永逸的任务ansi ble multi-B 3600-P 0-a /path/to/fire-and-forget-script。嘘检查日志文件可用多s-a 尾/变量/日志/消息管理时间单位作业ansi ble multi-s-m cron-a name= daily-cron-all-servers \ hour=4 job=/path/to/daily-script。嘘
ansi ble multi-s-m cron-a name= daily-cron-all-servers state=absent 删掉转载于:https://www。cnblogs。com/顾小北/p/8251127.html
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。