首页 > 系统相关 >Ansible(ubuntu)

Ansible(ubuntu)

时间:2024-06-14 10:00:07浏览次数:13  
标签:ansible server1 private Ansible ssh key ubuntu user

1.安装Ansible

sudo apt update
sudo apt install ansible

2.配置ansible主机

1.将本机的密钥添加到目标服务器上

2.追加公钥 echo '$(cat ~/.ssh/id_rsa.pub)' >> ~/.ssh/authorized_keys
远程追加ssh username@remote_host "echo '$(cat ~/.ssh/id_rsa.pub)' >> ~/.ssh/authorized_keys"
ssh [email protected] "echo '$(cat /root/.ssh/id_rsa.pub)' >> /home/ubuntu/.ssh/authorized_keys"
3.编写Ansible 主机清单文件(通常是 /etc/ansible/hosts)列出它将管理的服务器。你可以配置这个文件,以包含主机组和对应的服务器。
示例 /etc/ansible/hosts 文件:
[goingbus]
goingbus.com ansible_host=43.153.66.136 ansible_user=ubuntu ansible_ssh_private_key_file=/root/.ssh/id_rsa
i.universalbus.cn ansible_host=119.45.191.212 ansible_user=ubuntu ansible_ssh_private_key_file=/root/.ssh/id_rsa

2.1常见的配置参数

ansible_host - 指定远程主机的IP地址。
server1 ansible_host=192.168.1.100

ansible_port - SSH端口,如果你不使用默认的端口22。
server1 ansible_port=2222

ansible_user - 用于SSH连接的用户名。
server1 ansible_user=myuser


ansible_ssh_pass - SSH密码(通常不推荐在清单文件中直接存储密码,而应使用Ansible Vault)。
server1 ansible_ssh_pass=mypassword


ansible_ssh_private_key_file - 用于SSH连接的私钥文件路径。
server1 ansible_ssh_private_key_file=/path/to/private/key


ansible_python_interpreter - 指定远程主机上Python解释器的路径。这在目标系统上未将Python配置为默认路径时非常有用。
server1 ansible_python_interpreter=/usr/bin/python3


ansible_connection - 连接类型,如 ssh(默认)、local、docker 等。
server1 ansible_connection=ssh


ansible_become - 是否提升权限(类似于sudo),默认为否。
server1 ansible_become=yes


ansible_become_method - 提升权限时使用的方法,默认是 sudo,还可以是 su 等。
server1 ansible_become_method=sudo


ansible_become_user - 提升权限后操作的用户,默认为 root。
server1 ansible_become_user=root


ansible_become_pass - 用于权限提升的密码。
server1 ansible_become_pass=rootpassword

3.Ansible 配置文件

Ansible 的行为可以通过编辑 /etc/ansible/ansible.cfg 配置文件来自定义。这个文件控制了诸如哪个清单文件被使用,使用哪个模块库,SSH 连接的参数等选项。

[defaults]
inventory = /etc/ansible/hosts
remote_user = your_user
private_key_file = /path/to/your/private.key
host_key_checking = False
retry_files_enabled = False


inventory: 指定清单文件的位置。 
remote_user: 默认远程用户。
private_key_file: SSH连接使用的私钥文件。
host_key_checking: 如果设置为 False,则在首次连接SSH时不检查主机密钥。

4.检查测试连接

验证安装并测试连接,可以使用 ansible 命令行工具对所有主机进行 ping 测试:

ansible all -m ping

5.运行

ansible-playbook script/ansible/production.yaml

如果没有在Ansible 配置文件中配置指定清单文件的位置,则可以在命令中指定
ansible-playbook -i /home/root_zqh/.ansible/hosts script/ansible/production.yaml

6.go 1.19安装

wget https://mirrors.ustc.edu.cn/golang/go1.19.linux-amd64.tar.gz

sudo tar -C /usr/local -xzf go1.19.linux-amd64.tar.gz

echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc

source ~/.bashrc

go version

7.swag安装

go install github.com/swaggo/swag/cmd/swag@latest

swag -v

标签:ansible,server1,private,Ansible,ssh,key,ubuntu,user
From: https://www.cnblogs.com/chunyouqudongwuyuan/p/18247191

相关文章

  • ubuntu22.04编译openwrt的lede-17.01一些错误的处理方式
    m4c-stack.c:55:26:error:missingbinaryoperatorbeforetoken“(“55|#elifHAVE_LIBSIGSEGV&&解决方法:wgethttps://raw.githubusercontent.com/keyfour/openwrt/2722d51c5cf6a296b8ecf7ae09e46690403a6c3d/tools/m4/patches/011-fix-sigstksz.patch-O......
  • DellR730安装ESXI Ubuntu安装显卡失败问题
    ESXI显卡直通车安装显卡驱动配置清单如下本地服务器型号:DellR730系统:ubuntu20.4显卡:NvidiaP40虚拟化操作系统:esxi6.7.0驱动版本:NVIDIA-Linux-x86_64-440.95.01.run 禁用Nouveau(这一步很关键)sudovi/etc/modprobe.d/blacklist-nouveau.conf添加如下内容blacklistn......
  • Ubuntu系统的基本教程
    Ubuntu系统的使用基本教程可以归纳为以下几个主要部分:1. 安装Ubuntu系统硬件要求:Ubuntu系统对硬件要求较低,但建议至少具有1GHz的处理器、2GB的内存、25GB的磁盘空间、1024x768的分辨率显示器和网络连接。下载镜像文件:前往Ubuntu官方网站下载最新的Ubuntu镜像文件,选择适合......
  • 【Ubuntu双系统】两块硬盘分别安装系统,一块硬盘安装Ubuntu 一块安装Windows
    【Ubuntu双系统】两块硬盘分别安装双系统,一块硬盘安装Ubuntu一块安装Windows前言安装Ubuntu前置操作安装过程参考文献前言机器情况:两块1T的硬盘,其中一块已安装Windows11现需在另一块硬盘上安装Ubuntu,该硬盘还未初始化Ubuntu安装参考教程来自:【ubuntu20.04】10分钟......
  • zabbix(ubuntu22.04)
    zabbix是一款监控软件,可监控各种网络参数,同时支持灵活的告警机制。常用术语主机(Host):需要监控的网络设备,可用IP或域名表示主机群组(Hostgroup):为了方面批量管理大量Host,我们会通过主机群组的方式设置一些通用的权限设置监控项(Item):一个特定监控指标的相关数据,这些数据来......
  • 【ubuntu】记住gitlab的登录账号密码
    一、场景   当我们拉取多个项目时,每次总要输入密码,http方式的时候  二、方法gitconfig--globalcredential.helperstore然后可以手动配置账号密码配置~/.gitconfig文件[user][email protected][credential]helper=store[f......
  • 【jmeter】ubuntu分布式jmeter报错:java.rmi.ConnectException: Connection refused to
    一、场景   由于高并发测试,服务器资源不够用,所以需要使用jmeter分布式进行测试,但是测试过程中报错:java.rmi.ConnectException:Connectionrefusedtohost:127.0.1.1;  二、问题原因   就是hostname-i如果返回的是127.0.1.1 三、处理方法   修改hostna......
  • Linux——ansible的应用
    要让ansible管理业务里的主机1.得先知道,有哪些主机  用IP地址,用主机名2.知道了有哪些主机以后,精细、细分管理  主机要用某些办法,分组管理在ansible里,要用一个东西:清单->inventoryinventory这个东西的存在形式ansible是为了人方便使用,为了简单所以,inventory,就是个......
  • 在ubuntu22.04下安装cursor
    在ubuntu22.04下安装cursor安装Cursor编程软件1.访问Cursor网站下载Linux版本的AppImage文件2.如果出现“dlopen():errorloadinglibfuse.so.2”错误,需要安装fuse。3.将Cursor添加到应用程序列表4.保存.desktop文件,Cursor就会出现在应用程序列表中。5.如果出现点击curs......
  • ubuntu在apt安装时出现的弹窗详解
    在一个全新安装的Ubuntu22.04LTS上,每次使用apt安装或更新软件包时,会出现一个Daemonsusingoutdatedlibraries弹窗,Whichserviceshouldberestarted?大概是下面这个样子: 这让我想起了windows上每次打开一个应用都会弹窗提示安全提醒,异曲同工啊。一脸懵的情况下,只能一......