惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Commits to openclaw:main
Recent Commits to openclaw:main
Simon Willison's Weblog
Simon Willison's Weblog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Schneier on Security
Cyberwarzone
Cyberwarzone
NISL@THU
NISL@THU
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
The Hacker News
The Hacker News
Schneier on Security
Schneier on Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
Scott Helme
Scott Helme
SecWiki News
SecWiki News
Security Latest
Security Latest
T
Threat Research - Cisco Blogs
L
LINUX DO - 最新话题
L
Lohrmann on Cybersecurity
TaoSecurity Blog
TaoSecurity Blog
K
Kaspersky official blog
Attack and Defense Labs
Attack and Defense Labs
P
Privacy & Cybersecurity Law Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LINUX DO - 热门话题
N
News and Events Feed by Topic
Know Your Adversary
Know Your Adversary
Forbes - Security
Forbes - Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google DeepMind News
Google DeepMind News
T
Tor Project blog
P
Palo Alto Networks Blog
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
O
OpenAI News
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AI
AI
N
News and Events Feed by Topic
博客园 - Franky
T
Threatpost
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Engineering at Meta
Engineering at Meta
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
B
Blog RSS Feed
Hacker News: Ask HN
Hacker News: Ask HN
D
Docker
博客园 - 三生石上(FineUI控件)

jobcher on 打工人日志

2023-12-21 打工人日报 2023-12-20 打工人日报 2023-12-19 打工人日报 2023-12-18 打工人日报 2023-12-17 打工人日报 2023-12-16 打工人日报 2023-12-15 打工人日报 2023-12-14 打工人日报 2023-12-13 打工人日报 2023-12-12 打工人日报 2023-12-11 打工人日报 2023-12-10 打工人日报 2023-12-09 打工人日报 2023-12-08 打工人日报 2023-12-07 打工人日报 2023-12-06 打工人日报 2023-12-05 打工人日报 2023-12-04 打工人日报 2023-12-03 打工人日报 2023-12-02 打工人日报 2023-12-01 打工人日报 2023-11-30 打工人日报 2023-11-29 打工人日报 2023-11-28 打工人日报 2023-11-27 打工人日报 2023-11-26 打工人日报 2023-11-25 打工人日报 2023-11-24 打工人日报 2023-11-23 打工人日报 2023-11-22 打工人日报 2023-11-21 打工人日报 2023-11-20 打工人日报 2023-11-19 打工人日报 2023-11-17 打工人日报 2023-11-16 打工人日报 2023-11-15 打工人日报 2023-11-14 打工人日报 2023-11-13 打工人日报 2023-11-12 打工人日报 2023-11-11 打工人日报 2023-11-10 打工人日报 2023-11-09 打工人日报 2023-11-08 打工人日报 2023-11-07 打工人日报 2023-11-06 打工人日报 2023-11-05 打工人日报 2023-11-04 打工人日报 2023-11-03 打工人日报 2023-11-02 打工人日报 2023-11-01 打工人日报 2023-10-31 打工人日报 2023-10-30 打工人日报 2023-10-29 打工人日报 2023-10-28 打工人日报 2023-10-27 打工人日报 2023-10-26 打工人日报 2023-10-25 打工人日报 2023-10-24 打工人日报 2023-10-23 打工人日报 2023-10-22 打工人日报 2023-10-21 打工人日报 2023-10-20 打工人日报 2023-10-19 打工人日报 2023-10-18 打工人日报 2023-10-17 打工人日报 2023-10-16 打工人日报 2023-10-15 打工人日报 2023-10-14 打工人日报 2023-10-13 打工人日报 2023-10-12 打工人日报 2023-10-11 打工人日报 2023-10-10 打工人日报 2023-10-09 打工人日报 2023-10-07 打工人日报 2023-10-06 打工人日报 2023-10-05 打工人日报 2023-10-04 打工人日报 2023-10-03 打工人日报 2023-10-02 打工人日报 2023-10-01 打工人日报 2023-09-30 打工人日报 2023-09-29 打工人日报 2023-09-28 打工人日报 2023-09-27 打工人日报 2023-09-26 打工人日报 2023-09-25 打工人日报 2023-09-24 打工人日报 2023-09-23 打工人日报 2023-09-22 打工人日报 2023-09-21 打工人日报 2023-09-20 打工人日报 2023-09-19 打工人日报 2023-09-18 打工人日报 2023-09-17 打工人日报 2023-09-16 打工人日报 2023-09-15 打工人日报 2023-09-14 打工人日报 2023-09-13 打工人日报 2023-09-12 打工人日报 2023-09-11 打工人日报
ansible 安装和部署
2021-12-30 · via jobcher on 打工人日志

ansible 安装和部署

Ansible 默认通过 SSH 协议管理机器.

安装 ansible

  1. 下载安装
1# ubuntu 安装
2apt-get install software-properties-common
3apt-add-repository ppa:ansible/ansible
4apt-get update
5apt-get install ansible
6# centos 安装
7yum install ansible
  1. 检查文件

ansible 配置

  1. 添加主机
1vim /etc/ansible/hosts
2#添加你需要添加的被控主机地址和IP
  1. 配置 SSH key 授权访问
1# 控制主机生成ssh 密钥对(一路回车)
2ssh-keygen -t rsa
3# 复制公钥IP到被控主机
4ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.2
5ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.3
6ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.4
7# ssh-copy-id命令会自动将id_rsa.pub文件的内容追加到远程主机root用户下.ssh/authorized_keys文件中。
  1. 更改 ansible 配置
1vim /etc/ansible/ansible.cfg
2
3#禁用每次执行ansbile命令检查ssh key host
4host_key_checking = False
5# 开启日志记录
6log_path = /var/log/ansible.log
  1. 测试
1# 控制主机
2ansible all -m ping

Inventory

  1. 配置组别
 1vim /etc/ansible/hosts
 2# 添加组别
 3
 4[pve]
 5192.168.0.2
 6192.168.0.3
 7192.168.0.4
 8
 9#测试
10ansible pve -m ping
  1. Inventory 参数 把你的 inventory 文件 和 变量 放入 git repo 中,以便跟踪他们的更新,这是一种非常推荐的方式.
参数作用
ansible_ssh_host将要连接的远程主机名.与你想要设定的主机的别名不同的话,可通过此变量设置.
ansible_ssh_portssh 端口号.如果不是默认的端口号,通过此变量设置.
ansible_ssh_user默认的 ssh 用户名
ansible_ssh_passssh 密码(这种方式并不安全,我们强烈建议使用 –ask-pass 或 SSH 密钥)
ansible_sudo_passsudo 密码(这种方式并不安全,我们强烈建议使用 –ask-sudo-pass)
ansible_sudo_exe (new in version 1.8)sudo 命令路径(适用于 1.8 及以上版本)
ansible_connection与主机的连接类型.比如:local, ssh 或者 paramiko. Ansible 1.2 以前默认使用 paramiko.1.2 以后默认使用 ‘smart’,‘smart’ 方式会根据是否支持 ControlPersist, 来判断’ssh’ 方式是否可行.
ansible_ssh_private_key_filessh 使用的私钥文件.适用于有多个密钥,而你不想使用 SSH 代理的情况.
ansible_shell_type目标系统的 shell 类型.默认情况下,命令的执行使用 ‘sh’ 语法,可设置为 ‘csh’ 或 ‘fish’.
ansible_python_interpreter目标主机的 python 路径.适用于的情况: 系统中有多个 Python, 或者命令路径不是"/usr/bin/python",比如 *BSD, 或者 /usr/bin/python

Roles

Roles 是基于已知文件结构自动加载某些变量文件,任务和处理程序的方法。按角色对内容进行分组,适合构建复杂的部署环境 Roles 目录结构:

 1site.yml
 2webservers.yml
 3fooservers.yml
 4roles/
 5common/
 6tasks/
 7handlers/
 8files/
 9templates/
10vars/
11defaults/
12meta/
13webservers/
14tasks/
15defaults/
16meta/
  • tasks 包含角色要执行的任务的主要列表
  • handlers 包含处理程序,此角色甚至在此角色之外的任何地方都可以使用这些处理程序
  • defaults 角色的默认变量
  • vars 角色的其他变量
  • files 包含可以通过此角色部署的文件
  • templates 包含可以通过此角色部署的模版
  • meta 为此角色定义一些元数据