- 浏览: 2486721 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Ansible 2019(1)Introduction and Installation on Ubuntu and CentOS
Ansible is using SSH, it can execute the shell commands.
Install Ansible on Ubuntu
> sudo apt-add-repository -y ppa:ansible/ansible
> sudo apt-get update
> sudo apt-get install ansible
> ansible --version
ansible 2.8.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/carl/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.15+ (default, Oct 7 2019, 17:39:04) [GCC 7.4.0]
Prepare 2 workers machines for ubuntu latest version
> wget http://mirror.lstn.net/ubuntu-releases/19.04/ubuntu-19.04-live-server-amd64.iso
Set Up Clean 19.04 Ubuntu Machines
Set Up Root Password
> sudo passwd root
Set Up IP information
> cd /etc/netplan/
> sudo vi 50-cloud-init.yaml
network:
ethernets:
enp0s3:
dhcp4: true
enp0s8:
dhcp4: no
addresses: [192.168.56.102/24]
gateway4: 192.168.56.0
nameservers:
addresses: [8.8.8.8,8.8.4.4]
version: 2
> sudo netplan apply
I try to verify on ubuntu-master, ubuntu-worker1, ubuntu-worker2, so the hosts file will be like this
> cat /etc/hosts
192.168.56.101 ubuntu-master
192.168.56.102 ubuntu-worker1
192.168.56.103 ubuntu-worker2
On the master machine, ubuntu-master, copy the keys to workers
> ssh-copy-id -i ~/.ssh/id_rsa.pub carl@ubuntu-worker1
> ssh-copy-id -i ~/.ssh/id_rsa.pub carl@ubuntu-worker2
Need to make the user execute sudo without password on all the workers
> sudo visudo
carl ALL=(ALL) NOPASSWD:ALL
Check workers list
> sudo vi /etc/ansible/hosts
ubuntu-master
[workers]
ubuntu-worker1
ubuntu-worker2
Try some commands and it works well
> ansible workers -u carl -a "df -h"
Promote password
> ansible workers -b -K -u carl -a "apt update"
No Password
>ansible workers -b -u carl -a "apt update"
Not working on ubuntu 19.04?
Solution:
https://askubuntu.com/questions/504652/adding-nopasswd-in-etc-sudoers-doesnt-work
https://www.tecrobust.com/run-sudo-command-without-password-in-ubuntu/
Need to add this line to the end of the file
carl ALL=(ALL) NOPASSWD:ALL
After that, these commands works
> ansible workers -b -u carl -a "apt update"
Playbook
> cat playbook.yml
---
- hosts: workers
become: true
become_user: carl
tasks:
- name: check disk
command: df -h
> ansible-playbook -u carl playbook.yml
Update the softwares there
> cat playbook.yml
---
- hosts: workers
become: true
become_user: carl
tasks:
- name: update
command: apt update
become_user: root
become_method: sudo
- name: install
command: apt dist-upgrade
become_user: root
become_method: sudo
Shutdown all the workers
> ansible workers -b -u carl -a "shutdown -h now"
Install on CentOS
> sudo yum install ansible
Check the version
> ansible --version
ansible 2.8.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/carl/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Generate SSH Key On CentOS
https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-centos7
> ssh-keygen
Copy the keys to workers
> ssh-copy-id -i ~/.ssh/id_rsa.pub rancher-worker1
> ssh-copy-id -i ~/.ssh/id_rsa.pub rancher-worker2
No password to execute sudo command
> sudo visudo
%wheel ALL=(ALL) NOPASSWD: ALL
Check workers list
> sudo vi /etc/ansible/hosts
rancher-home
[workers]
rancher-worker1
rancher-worker2
Try some commands and it works well
> ansible workers -u carl -a "df -h"
Promote password
> ansible workers -b -K -u carl -a 'yum update'
No Password
> ansible workers -b -u carl -a 'yum update'
It can be more complex if we need it to be
---
- hosts: sillycat-redis:sillycat-db:sillycat-els
remote_user: centos
tasks:
- name: curl
shell: 'curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.2.1-x86_64.rpm'
- name: rpm
shell: 'rpm -vi metricbeat-7.2.1-x86_64.rpm'
become: yes
become_user: root
become_method: sudo
- name: copy
copy: src=./etc/metricbeat.yml dest=/etc/metricbeat/metricbeat.yml
become: yes
become_user: root
become_method: sudo
- name: enable
shell: 'metricbeat modules enable system'
become: yes
become_user: root
become_method: sudo
- name: setup
shell: 'metricbeat setup'
become: yes
become_user: root
become_method: sudo
- name: start
shell: 'service metricbeat start'
become: yes
become_user: root
become_method: sudo
- name: auto start
shell: 'systemctl enable metricbeat'
become: yes
become_user: root
become_method: sudo
- name: rm install file
shell: 'rm -f metricbeat-7.2.1-x86_64.rpm'
- hosts: sillycat-redis
remote_user: centos
tasks:
- name: enable
shell: 'metricbeat modules enable redis'
become: yes
become_user: root
become_method: sudo
- name: restart
shell: 'systemctl restart metricbeat'
become: yes
become_user: root
become_method: sudo
- hosts: sillycat-db
remote_user: centos
tasks:
- name: enable
shell: 'metricbeat modules enable mysql'
become: yes
become_user: root
become_method: sudo
- name: restart
shell: 'systemctl restart metricbeat'
become: yes
become_user: root
become_method: sudo
- hosts: sillycat-els
remote_user: centos
tasks:
- name: enable
shell: 'metricbeat modules enable elasticsearch'
become: yes
become_user: root
become_method: sudo
- name: restart
shell: 'systemctl restart metricbeat'
become: yes
become_user: root
become_method: sudo
References:
https://www.cnblogs.com/sparkdev/p/9905290.html
https://www.ansible.com/
https://github.com/ansible/ansible
https://docs.ansible.com/ansible/latest/index.html
https://stackoverflow.com/questions/25582740/missing-sudo-password-in-ansible
https://askubuntu.com/questions/504652/adding-nopasswd-in-etc-sudoers-doesnt-work
Ansible is using SSH, it can execute the shell commands.
Install Ansible on Ubuntu
> sudo apt-add-repository -y ppa:ansible/ansible
> sudo apt-get update
> sudo apt-get install ansible
> ansible --version
ansible 2.8.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/carl/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.15+ (default, Oct 7 2019, 17:39:04) [GCC 7.4.0]
Prepare 2 workers machines for ubuntu latest version
> wget http://mirror.lstn.net/ubuntu-releases/19.04/ubuntu-19.04-live-server-amd64.iso
Set Up Clean 19.04 Ubuntu Machines
Set Up Root Password
> sudo passwd root
Set Up IP information
> cd /etc/netplan/
> sudo vi 50-cloud-init.yaml
network:
ethernets:
enp0s3:
dhcp4: true
enp0s8:
dhcp4: no
addresses: [192.168.56.102/24]
gateway4: 192.168.56.0
nameservers:
addresses: [8.8.8.8,8.8.4.4]
version: 2
> sudo netplan apply
I try to verify on ubuntu-master, ubuntu-worker1, ubuntu-worker2, so the hosts file will be like this
> cat /etc/hosts
192.168.56.101 ubuntu-master
192.168.56.102 ubuntu-worker1
192.168.56.103 ubuntu-worker2
On the master machine, ubuntu-master, copy the keys to workers
> ssh-copy-id -i ~/.ssh/id_rsa.pub carl@ubuntu-worker1
> ssh-copy-id -i ~/.ssh/id_rsa.pub carl@ubuntu-worker2
Need to make the user execute sudo without password on all the workers
> sudo visudo
carl ALL=(ALL) NOPASSWD:ALL
Check workers list
> sudo vi /etc/ansible/hosts
ubuntu-master
[workers]
ubuntu-worker1
ubuntu-worker2
Try some commands and it works well
> ansible workers -u carl -a "df -h"
Promote password
> ansible workers -b -K -u carl -a "apt update"
No Password
>ansible workers -b -u carl -a "apt update"
Not working on ubuntu 19.04?
Solution:
https://askubuntu.com/questions/504652/adding-nopasswd-in-etc-sudoers-doesnt-work
https://www.tecrobust.com/run-sudo-command-without-password-in-ubuntu/
Need to add this line to the end of the file
carl ALL=(ALL) NOPASSWD:ALL
After that, these commands works
> ansible workers -b -u carl -a "apt update"
Playbook
> cat playbook.yml
---
- hosts: workers
become: true
become_user: carl
tasks:
- name: check disk
command: df -h
> ansible-playbook -u carl playbook.yml
Update the softwares there
> cat playbook.yml
---
- hosts: workers
become: true
become_user: carl
tasks:
- name: update
command: apt update
become_user: root
become_method: sudo
- name: install
command: apt dist-upgrade
become_user: root
become_method: sudo
Shutdown all the workers
> ansible workers -b -u carl -a "shutdown -h now"
Install on CentOS
> sudo yum install ansible
Check the version
> ansible --version
ansible 2.8.5
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/carl/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Generate SSH Key On CentOS
https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-centos7
> ssh-keygen
Copy the keys to workers
> ssh-copy-id -i ~/.ssh/id_rsa.pub rancher-worker1
> ssh-copy-id -i ~/.ssh/id_rsa.pub rancher-worker2
No password to execute sudo command
> sudo visudo
%wheel ALL=(ALL) NOPASSWD: ALL
Check workers list
> sudo vi /etc/ansible/hosts
rancher-home
[workers]
rancher-worker1
rancher-worker2
Try some commands and it works well
> ansible workers -u carl -a "df -h"
Promote password
> ansible workers -b -K -u carl -a 'yum update'
No Password
> ansible workers -b -u carl -a 'yum update'
It can be more complex if we need it to be
---
- hosts: sillycat-redis:sillycat-db:sillycat-els
remote_user: centos
tasks:
- name: curl
shell: 'curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.2.1-x86_64.rpm'
- name: rpm
shell: 'rpm -vi metricbeat-7.2.1-x86_64.rpm'
become: yes
become_user: root
become_method: sudo
- name: copy
copy: src=./etc/metricbeat.yml dest=/etc/metricbeat/metricbeat.yml
become: yes
become_user: root
become_method: sudo
- name: enable
shell: 'metricbeat modules enable system'
become: yes
become_user: root
become_method: sudo
- name: setup
shell: 'metricbeat setup'
become: yes
become_user: root
become_method: sudo
- name: start
shell: 'service metricbeat start'
become: yes
become_user: root
become_method: sudo
- name: auto start
shell: 'systemctl enable metricbeat'
become: yes
become_user: root
become_method: sudo
- name: rm install file
shell: 'rm -f metricbeat-7.2.1-x86_64.rpm'
- hosts: sillycat-redis
remote_user: centos
tasks:
- name: enable
shell: 'metricbeat modules enable redis'
become: yes
become_user: root
become_method: sudo
- name: restart
shell: 'systemctl restart metricbeat'
become: yes
become_user: root
become_method: sudo
- hosts: sillycat-db
remote_user: centos
tasks:
- name: enable
shell: 'metricbeat modules enable mysql'
become: yes
become_user: root
become_method: sudo
- name: restart
shell: 'systemctl restart metricbeat'
become: yes
become_user: root
become_method: sudo
- hosts: sillycat-els
remote_user: centos
tasks:
- name: enable
shell: 'metricbeat modules enable elasticsearch'
become: yes
become_user: root
become_method: sudo
- name: restart
shell: 'systemctl restart metricbeat'
become: yes
become_user: root
become_method: sudo
References:
https://www.cnblogs.com/sparkdev/p/9905290.html
https://www.ansible.com/
https://github.com/ansible/ansible
https://docs.ansible.com/ansible/latest/index.html
https://stackoverflow.com/questions/25582740/missing-sudo-password-in-ansible
https://askubuntu.com/questions/504652/adding-nopasswd-in-etc-sudoers-doesnt-work
发表评论
-
Update Site will come soon
2021-06-02 04:10 1609I am still keep notes my tech n ... -
Stop Update Here
2020-04-28 09:00 260I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 430NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 310Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 321Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 291Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 378Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 373Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 327Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 397VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 334Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 415NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 359Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 292Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 208GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 390GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 275GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 264Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 259Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 252Serverless with NodeJS and Tenc ...
相关推荐
用于生产环境centos6.8离线安装ansible包
Ansible-docker-centos7-ansible.zip,用于Ansible Playbook和角色测试的CentOS 7 Docker容器。CentOS 7 Ansible测试图像,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。
用于离线环境,Centos7系统一键安装ansible服务,本人测试环境为:Centos7.5最小化系统。解压后直接进入此目录通过yum localinstall -y ansible命令安装即可
centos6 ansible离线安装 ,直接执行rpm -ivh --force --nodes *.rpm
Among the many configuration management tools available, Ansible has some distinct advantages—it’s minimal in nature, you don’t need to install anything on your nodes, and it has an easy learning ...
ansible centos6.5安装及配置详细教程,亲测可运行。
centos7.6实测ansible2.9.9-1安装,包含安装文档以及所用到的所有RPM包,解决所有依赖,包含依赖的依赖 错误:依赖检测失败: PyYAML 被 ansible-2.9.9-1.el7ae.noarch 需要 python-jinja2 被 ansible-2.9.9-1.el7...
kubernets centos ansible playbook 安装 国内镜像源
Ansible2.4 CentOS7 离线安装包。欢迎参考博文使用应用http://blog.csdn.net/lampqiu/article/details/79408139
centos7 ansible离线安装 ,直接执行rpm -ivh --force --nodes *.rpm
通过apt-get -d install ansible获取得到的ansible离线安装所需要的所有安装包,根据测试按照依赖的顺序写的脚本,只用执行包内.sh文件即可安装
教你在 Centos8 中安装并使用 Ansible.doc
Ansible-ansible-ubuntu.zip,ansible脚本设置ubuntu桌面/服务器ansible ubuntu安装程序,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。
ansible部署包,只需将目录上传到任意目录下,添加被控主机IP,使用脚本发送公钥
Ansible 操作系统centos7安装包 rpm安装包 1、只需下载安装包进行解压 2、根据依赖进行逐个安装即可 3、安装完成后通过ansible、ansible-playbook等命令执行操作
本文档在CentOS 7上安装最新版本Ansible AWX 20.1.1自动化运维管理系统,当前网络中均是老版本的安装配置资料,和最新版本基本没有什么参考价值,githup的介绍确实理解起来非常晦涩,在通过探索终于可以完成了一个...
Ansible-docker-ubuntu1804-ansible.zip,ubuntu 18.04 LTS(仿生)Docker容器用于Ansible Playbook和角色测试。ubuntu 18.04 LTS(仿生)Ansible测试图像,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理...
离线安装包,亲测可用
Ansible-docker-ubuntu1604-ansible.zip,用于ansible playbook和角色测试的ubuntu 16.04 lts(xenial)docker容器。,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。
Ansible-packer-ubuntu-1604.zip,打包程序示例-使用ansible provisionerpacker示例的ubuntu 16.04 minimal vagrant box-ubuntu 16.04 minimal vagrant box,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理...