YueKi WiKi

个人维基百科与知识管理

用户工具

站点工具


服务器:ansible

ansible 在 ubuntu 上的安装经验

sudo apt-get install python ansible
sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

host 列表说明

指明用户

 ansible_user=root

批量推送公钥匙

需要sshpass

sudo apt install sshpass

生产配对密钥

ssh-keygen -t rsa

编写推送公钥的yml文件

[root@server81 ansible]# vim push-ssh.yaml 

# Using alternate directory locations:
  - hosts: testservers
    user: root
    tasks:
     - name: ssh-copy
       authorized_key: user=root key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
       tags:
         - sshkey

禁用公钥

[root@server81 ansible]# vim /etc/ansible/ansible.cfg
# uncomment this to disable SSH key host checking
host_key_checking = False

推送

ansible-playbook push-ssh.yaml

管理 windows

windows 主机配置

powershell版本,需要升级 4.0

get-host

更改powershell执行策略为remotesigned

get-executionpolicy
set-executionpolicy remotesigned
  1. 配置winrm service并启动服务
winrm quickconfig
  1. 查看winrm service启动监听状态
winrm enumerate winrm/config/listener
  1. 修改winrm配置,启用远程连接认证
winrm set winrm/config/service/auth '@{Basic="true"}'

winrm set winrm/config/service '@{AllowUnencrypted="true"}'
5985端口可访问

安装 winrm

pip install pywinrm paramiko PyYAML Jinja2 httplib2 six

ping 方法

ping linux

 ansible all -m ping

ping windows

 ansible all -m win_ping

常用命令

window 加 win_

// 新建目录
sudo ansible l -m file -a 'dest=/etc/test state=directory'
// 同步文件
ansible w -m copy -a 'src=/etc/hosts dest=/etc/test/'