推广 热搜: page  数据  小红  红书  考试  论文  数据分析  关键词  哪些  搜索 

网站建设三要素/关键词优化分析工具

   日期:2024-12-23     移动:https://sicmodule.kub2b.com/mobile/quote/10579.html

2.推送单个公钥到远程机器
格式: ssh-copy-id -i ~/.ssh/id_rsa.pub username@[ip,hostname]

ssh-copy-id -i ~/.ssh/id_rsa.pub username@192.168.198.x

3.添加ansible hosts
编辑/etc/ansible/hosts,没有则创建些文件。

格式:【主机名】 【主机地址】 【主机密码】 默认是root用户来进行的

[all]
1 ansible_ssh_user="root" ansible_ssh_host=192.168.198.131 ansible_ssh_pass="123456"
2 ansible_ssh_user="root" ansible_ssh_host=192.168.198.134 ansible_ssh_pass="123456"
3 ansible_ssh_user="root" ansible_ssh_host=192.168.198.141 ansible_ssh_pass="123456"

新版的ansible(2.4) hosts有更新, 用以下方式

[all]
192.168.198.131 ansible_user=root ansible_ssh_pass="123456"
192.168.198.141 ansible_user=root ansible_ssh_pass="123456"
192.168.198.134 ansible_user=root ansible_ssh_pass="123456"

4.批量推送公钥到远程机器
机器多的情况下,使用ssh-copy-id方法有些费时,使用ansible-playbook推送ymal,这里使用到了authoried_keys模块,可以参考 http://docs.ansible.com/authorized_key_module.html

[root@mha ansible]# ls
ansible.cfg hosts push.ssh.ymal roles
[root@mha ansible]# cat push.ssh.ymal

  

5.执行推送命令
ansible-playbook push.ssh.ymal
[root@mha ansible]# ansible-playbook push.ssh.ymal

PLAY [all] **

TASK [Gathering Facts] **
ok: [192.168.198.134]
ok: [192.168.198.141]
ok: [192.168.198.131]

TASK [ssh-copy] *****
ok: [192.168.198.134]
ok: [192.168.198.141]
changed: [192.168.198.131]

新增用户和创建密码
[root@nginx-proxy-01-keepalived ansible]# ansible nginx -m shell -a "useradd wsw && echo "123456"| passwd --stdin wsw"
192.168.198.131 | SUCCESS | rc=0 >>
Changing password for user wsw.
passwd: all authentication tokens updated successfully.

192.168.198.134 | SUCCESS | rc=0 >>
Changing password for user wsw.
passwd: all authentication tokens updated successfully.

192.168.198.145 | SUCCESS | rc=0 >>
Changing password for user wsw.
passwd: all authentication tokens updated successfully.

192.168.198.144 | SUCCESS | rc=0 >>
Changing password for user wsw.
passwd: all authentication tokens updated successfully.

三、检查主机组或者是单一个主机
[root@mha ansible-tower-setup-3.1.0]# ansible all -m shell -a "mysql -uroot -p123456 -e 'use test;show tables'"
192.168.198.134 | SUCCESS | rc=0 >>
Tables_in_test
t3
t4
t44
t5
tt1

192.168.198.131 | FAILED | rc=127 >>
/bin/sh: mysql: command not found

四、ansible-playbook
1、关于git pull
[root@mha ansible-for-devops]# cat git.yml

  

2、关于git pull紧接着checkout branch
[root@mha ansible-for-devops]# cat git.yml

本文地址:https://sicmodule.kub2b.com/quote/10579.html     企库往 https://sicmodule.kub2b.com/ , 查看更多

特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


0相关评论
相关最新动态
推荐最新动态
点击排行
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2020018471号