Linux学习-Ansible(一)

打印 上一主题 下一主题

主题 1860|帖子 1860|积分 5590

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
情况- Rocky-Linux8.6

安装部署Ansible

  1. # 安装ansible
  2. [root@harbor ansible]# dnf install -y ansible-core
  3. #查看安装信息
  4. [root@harbor ansible]# ansible-doc --version
  5. ansible-doc [core 2.12.2]
  6.   config file = /root/ansible/ansible.cfg
  7.   configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  8.   ansible python module location = /usr/lib/python3.8/site-packages/ansible
  9.   ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  10.   executable location = /usr/bin/ansible-doc
  11.   python version = 3.8.12 (default, May 10 2022, 23:46:40) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]
  12.   jinja version = 2.10.3
  13.   libyaml = True
  14. : << EOF
  15. Ansible认证方式有密码认证和公私钥认证两种方式
  16. EOF
  17. # 为“ssh”生成、管理和转换认证密钥,它支持RSA和DSA两种认证密钥,默认RSA
  18. [root@harbor ansible]# ssh-keygen
  19. Generating public/private rsa key pair.
  20. Enter file in which to save the key (/root/.ssh/id_rsa):
  21. /root/.ssh/id_rsa already exists.
  22. Overwrite (y/n)?
  23. #ssh-copy-id可以把本地主机的公钥复制到远程主机的authorized_keys文件上
  24. [root@harbor ansible]# ssh-copy-id -i /root/.ssh/id_rsa 192.168.29.161
  25. /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
  26. The authenticity of host '192.168.29.161 (192.168.29.161)' can't be established.
  27. ECDSA key fingerprint is SHA256:77a8CWnJMqyZH4QnCrcwH81FefxPv38r7+pw5yO0OJI.
  28. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
  29. /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
  30. /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
  31. root@192.168.29.161's password:
  32. Number of key(s) added: 1
  33. Now try logging into the machine, with:   "ssh '192.168.29.161'"
  34. and check to make sure that only the key(s) you wanted were added.
  35. [root@harbor ansible]# pwd
  36. /root/ansible
  37. #配置Ansible配置文件和主机列表
  38. [root@harbor ansible]# ls
  39. ansible.cfg  hostlist
  40. [root@harbor ansible]# cat ansible.cfg hostlist
  41. [defaults]
  42. inventory         = hostlist        #主机清单列表文件
  43. host_key_checking = False           #Ansible连接客户端时的SSH主机密钥检查,避免第一次连接到新主机时出现连接确认,即首交连接是否需要key认证
  44. #主机清单文件中可以是IP地址或主机名
  45. [web]
  46. 192.168.29.161
  47. 192.168.29.162
  48. # 查看web组下的主机列表
  49. [root@harbor ansible]# ansible web --list
  50.   hosts (2):
  51.     192.168.29.161
  52.     192.168.29.162
  53. # 向web主机组下主机发送ping命令
  54. [root@harbor ansible]# ansible web -m ping
  55. 192.168.29.161 | SUCCESS => {
  56.     "ansible_facts": {
  57.         "discovered_interpreter_python": "/usr/libexec/platform-python"
  58.     },
  59.     "changed": false,
  60.     "ping": "pong"
  61. }
  62. 192.168.29.162 | SUCCESS => {
  63.     "ansible_facts": {
  64.         "discovered_interpreter_python": "/usr/libexec/platform-python"
  65.     },
  66.     "changed": false,
  67.     "ping": "pong"
  68. }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

篮之新喜

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表