Ansible
准备¶
DNS 解析¶
cat >> /etc/hosts <<EOF
192.168.205.68 h1
192.168.205.69 h2
192.168.205.70 h3
192.168.205.73 m
EOF
安装¶
sudo apt-get update
sudo apt-get -y install python3-pip
pip3 install ansible
export PATH=$PATH:$HOME/.local/bin
SSH KEY¶
sudo cp /var/root/Library/Application\ Support/multipassd/ssh-keys/id_rsa ${PATH_CODE}
概念¶
Inventory¶
# ansible.cfg
[defaults]
inventory = hosts
# hosts
[all]
h[1:3]
[hadoop]
h[1:3]
[all:vars]
ansible_ssh_user=ubuntu
AdHoc¶
ansible localhost -m ping [-o]
ansible all -m file -a "path=/opt/hadoop-3.3.4 state=absent" -b
Playbook¶
语法检查¶
ansible-playbook <YAML> --syntax-check
ansible-lint
工作原理¶
内置变量¶
ansible h1 -m debug -a 'msg={{ hostvars }}'
实战应用¶
环境变量¶
/etc/profile.d/java.sh
。
服务启动¶
资源¶
最后更新: September 10, 2023