一、 更新系统
-
sudo apt update && sudo apt -y upgrade
-
sudo reboot
二、安装ansible
-
sudo apt install ansible
-
ansible --version
-
修改ansible主机的主机清单,加入你要执行的节点地址。
vim /etc/ansible/hosts
[web]
192.168.37.140
192.168.37.141
-
测试结果 ansible all -m ping 192.168.37.140 | SUCCESS => { "changed": false, "ping": "pong" } 192.168.37.141 | SUCCESS => { "changed": false, "ping": "pong" }
-
免密ssh-key(可选)
ssh-keygen
ssh-copy-id ip地址
去掉yes/no的询问
-
vim /etc/ssh/ssh_confih
StrictHostKeyChecking no
-
systemctl restart sshd
-
-
安装docker
-
安装依赖
sudo apt-get update sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
-
安装GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
-
写入安装源
-
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
-
更新并安装doxker-ce
sudo apt-get -y update sudo apt-get -y install docker-ce
-
-
下载安装docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.26.2/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version
-
安装Nodejs和NPM
sudo apt install -y nodejs npm sudo npm install npm --global
-
安装docker相关python库
sudo apt install python3-pip pwgen sudo pip3 install requests==2.14.2
-
下载并上传ansible awx
https://links.jianshu.com/go?to=https%3A%2F%2Fgithub.com%2Fansible%2Fawx%2Farchive%2F3.0.0.tar.gz
-
解压进入awx目录
cd awx/installer/
pwgen -N 1 -s 30(复制生成的key)
-
编辑当前目录的inventory文件如下
localhost ansible_connection=local ansible_python_interpreter="/usr/bin/env python3"
[all:vars] dockerhub_base=ansible awx_task_hostname=awx awx_web_hostname=awxweb postgres_data_dir=/tmp/pgdocker host_port=80 host_port_ssl=443 docker_compose_dir=/tmp/awxcompose pg_username=awx pg_password=awxpass pg_database=awx pg_port=5432 rabbitmq_password=awxpass rabbitmq_erlang_cookie=cookiemonster admin_user=admin admin_password=StrongAdminpassword create_preload_data=True secret_key=(这里为上方key) project_data_dir=/tmp/project
-
执行安装
apt install python-docker
sudo ansible-playbook -i inventory install.yml