- 浏览: 2550763 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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 1676I am still keep notes my tech n ... -
Stop Update Here
2020-04-28 09:00 315I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 474NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 367Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 367Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 335Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 429Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 434Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 373Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 454VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 384Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 475NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 421Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 336Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 246GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 450GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 325GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 312Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 317Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 291Serverless with NodeJS and Tenc ...
相关推荐
1. **下载所需文件**:在有网络连接的机器上,访问官方或镜像站点下载适用于CentOS 7.9的Ansible RPM包以及相关依赖。将这些文件放入一个目录,并打包成`ansible_centos7_9_2009.tar.gz`。 2. **传输到目标服务器**...
Ansible 在 Centos8 中的安装和使用 Ansible 是一个开源的配置管理工具,用于自动化任务、部署应用程序。使用 Ansible,您可以自动执行日常任务,例如更新系统、安装软件、和配置服务。 Ansible 基本信息 * 节点...
ansible centos6.5安装及配置详细教程,亲测可运行。
2. `ansible_2.5.1+dfsg-1ubuntu0.1_all.deb`:Ansible的主要安装包,版本为2.5.1,适用于Ubuntu 16.04。 3. `libc6_2.27-3ubuntu1_amd64.deb`:GNU C库,是大多数Linux系统的核心部分,为应用程序提供基本的函数...
在离线环境中,对CentOS 7最小化系统进行Ansible的安装可能是一项挑战,因为通常需要网络连接来获取所需的依赖项。然而,通过预先准备一个包含所有必要依赖的压缩包,我们可以克服这一难题。以下是关于如何在无网络...
针对“centos6 ansible离线安装 全量rpm环境安装包.zip”这个主题,我们将深入探讨如何在CentOS 6系统上使用Ansible进行离线安装,并通过RPM包进行全量环境的搭建。 首先,CentOS 6是Red Hat Enterprise Linux的一...
Ansible-docker-centos7-ansible.zip,用于Ansible Playbook和角色测试的CentOS 7 Docker容器。CentOS 7 Ansible测试图像,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。
1. **Ansible 安装**: 在CentOS 7上安装Ansible,可以通过Yum包管理器进行,运行`sudo yum install -y ansible`命令即可。确保系统已更新且配置了正确的软件源。 2. **Ansible 主机列表**: Ansible 需要一个主机...
1. Python 2.7:Ansible 2.4.2 需要 Python 2.7 运行。 2. Python Setuptools:用于管理 Python 包。 3. GCC 编译器:用于编译源代码。 4. OpenSSH-clients:用于 SSH 连接。 5. Python-devel:用于 Python 开发,...
centos7.6实测ansible2.9.9-1安装,包含安装文档以及所用到的所有RPM包,解决所有依赖,包含依赖的依赖 错误:依赖检测失败: PyYAML 被 ansible-2.9.9-1.el7ae.noarch 需要 python-jinja2 被 ansible-2.9.9-1.el7...
在之前的教程中 ,我向您展示了如何通过docker 部署Ansible AWX。 同时,我发现了两 个为AWX 构建rpm 包的项目。 因此,在本教程中,我将向您展示如何在CentOS 7 上从RPM 文件安装Ansible AWX。Ansible AWX 是...
Ansible2.4 CentOS7 离线安装包。欢迎参考博文使用应用http://blog.csdn.net/lampqiu/article/details/79408139
如果`centos_7_1_ansible.sh`脚本包含了额外的配置或者自动化步骤,你需要赋予它执行权限,然后运行`chmod +x centos_7_1_ansible.sh`和`./centos_7_1_ansible.sh`。这个脚本可能会帮助你完成如设置环境变量、启动...
对于 CentOS 7 这样的Linux操作系统,Ansible提供了简单易用的接口来管理服务器集群,无需在目标主机上安装任何代理。本篇文章将深入探讨如何在CentOS 7环境中离线安装Ansible。 首先,"centos7 ansible离线安装...
在这个场景下,"kubernetes centos ansible playbook 安装 国内镜像源"描述了一个使用Ansible Playbook在CentOS系统上安装Kubernetes,并利用国内镜像源加速下载过程的过程。 首先,让我们详细探讨一下每个组成部分...
1. `ansible-2.7.10-1.el7.noarch.rpm`:这是Ansible的主要二进制包,版本为2.7.10,适用于EL7(即CentOS 7)平台,采用noarch架构,意味着它对处理器架构不敏感,可以在任何架构上运行。 2. `python-babel-0.9.6-8...
1. **准备Ansible RPM包**:在有互联网连接的机器上,访问官方仓库或镜像站点,找到适用于CentOS 6.8的Ansible RPM包,下载并将其压缩成tar.gz或zip格式。 2. **传输RPM包**:将下载好的压缩文件通过物理介质(如...
在CentOS 7操作系统上安装Ansible,通常需要通过RPM包来完成。以下是关于"centos 7 安装ansible 的rpm包与其相关的rpm依赖包"的详细解释。 首先,我们来看标题中提到的"rpm包"。RPM(Red Hat Package Manager)是...
Ansible-ansible-ubuntu.zip,ansible脚本设置ubuntu桌面/服务器ansible ubuntu安装程序,ansible是一个简单而强大的自动化引擎。它用于帮助配置管理、应用程序部署和任务自动化。