设为首页 收藏本站
查看: 1215|回复: 0

[经验分享] 《Ansible权威指南》笔记(1)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2018-1-2 19:23:25 | 显示全部楼层 |阅读模式
  2016-12-23
  读这本《Ansible权威指南》学习ansible,根据本书内容和网上的各种文档,以及经过自己测试,写出以下笔记。另,这本书内容很好,但印刷错误比较多,作者说第二版会改进,还没买的小伙伴们可以买第二版。
  一、安装
  1、安装要求:
  控制服务器:需要安装Python2.6/2.7
  被管理服务器:需要安装Python2.4 以上版本,若低于Python2.5 需要安装pythonsimplejson;若启用了selinux,则需要安装libselinux-python
  2、yum安装
  yum install ansible -y
  安装方式很多,个人推荐使用epel源安装,epel源安装方式不再赘述。截至目前,epel源安装的是2.2版。
  3、简单配置
  vim /etc/ansible/ansible.cfg    默认配置文件,读取配置文件的顺序是当前目录——当前用户家目录——/etc/ansible/ansible.cfg(该顺序未验证,建议在统一的地方配置,以免混乱)
  #remote_user = root    默认使用的远程连接用户
  vim /etc/ansible/hosts    Inventory文件的默认位置,指定所要管理的主机安装
  二、ssh密钥登陆
  ansilbe采用ssh的方式管理节点,为了方便管理,使用密钥方式面密码登陆被管理节点。
  1、生成rsa格式密钥
  ssh-keygen -t rsa
  2、把公钥写入到远端主机的~/.ssh/authorized_keys
  ssh-copy-id username@192.168.1.50
  3、管理机设置默认远程用户
  vim /etc/ansible/ansible.cfg
  remote_user = username
  三、ansible命令
  1、ansible    临时的一次性操作
  Usage: ansible <host-pattern> [options]
  host-pattern可以是域名,IP,也可以在/etc/ansible/hosts指定
  options
  -m    后接模块
  -a    后接模块参数
  -u    指定用户名
  -f    启动的并发线程数
  例:
  ansible all -m ping
  ansible all -m copy -a "src=/etc/fstab dest=/tmp/fatab owner=root group=root mode=644 backup=yes"
  报错:
  The authenticity of host '[192.168.99.43]:22051 ([192.168.99.43]:22)' can't be established.
  RSA key fingerprint is 5e:9d:5c:4c:e8:cd:6e:78:70:a2:04:1c:5f:6f:3a:1e.
  Are you sure you want to continue connecting (yes/no)? The authenticity of host '[192.168.99.248]:22051 ([192.168.99.248]:22)' can't be established.
  RSA key fingerprint is 64:d9:ef:67:6a:d5:37:ff:70:2f:06:d2:35:d1:6b:a2.
  Are you sure you want to continue connecting (yes/no)? The authenticity of host '[192.168.99.247]:22051 ([192.168.99.247]:22)' can't be established.
  解决方法:
  sed -i 's/^#host_key_checking = False/host_key_checking = False/' /etc/ansible/ansible.cfg
  2、ansible-doc    查看模块文档
  Usage: ansible-doc [options] [module...]
  Options:
  -h, --help            show this help message and exit
  -l, --list            List available modules
  -M MODULE_PATH, --module-path=MODULE_PATH
  specify path(s) to module library (default=None)
  -s, --snippet         Show playbook snippet for specified module(s)
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable
  connection debugging)
  --version             show program's version number and exit
  ansible-doc 模块名    模块说明
  ansible-doc -s 模块名    简要说明
  ansible-doc -l    报错:
[DEPRECATION WARNING]: docker is kept for backwards compatibility but usage is discouraged. The module documentation details page may explain more about this rationale..

  This feature will be removed in

  a future>
[ERROR]: unable to parse /usr/lib/python2.6/site-packages/ansible/modules/extras/cloud/misc/rhevm.py

  ERROR! module rhevm has a documentation error formatting or is missing documentation
  解决方法:
  sed -i 's/^#deprecation_warnings = True/deprecation_warnings = False/' /etc/ansible/ansible.cfg
  rm -f /usr/lib/python2.6/site-packages/ansible/modules/extras/cloud/misc/rhevm.py
  3、ansible-playbook    读取事先写好的playbook,可以理解为按一定条件组成的ansible任务集
  Usage: ansible-playbook playbook.yml
  4、ansible-galaxy    上传下载Roles,Roles地址https://galaxy.ansible.com/
  Usage: ansible-galaxy [delete|import|info|init|install|list|login|remove|search|setup] [--help] [options] ...
  5、ansible-pull    pull模式(ansible默认push模式),用于数量巨大的机器配置,以及没有网络连接的主机上运行ansible。
  Usage: ansible-pull -U <repository> [options]
  -U    URL of the playbook repository
  6、ansible-vault    用于配置文件加密
  ansible-vault [create|decrypt|edit|encrypt|rekey|view] [--help] [options] vaultfile.yml
  例:
  ansible-vault encrypt a.yml    加密并设置解密密码,加密后打开为乱码
  ansible-vault decrypt a.yml    解密
  7、ansible-console    进入类似于shell的交互模式

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-430910-1-1.html 上篇帖子: Ansible_自动化运维《Ansible之命令-2》 下篇帖子: Ansible 系列之 Ad-Hoc介绍及使用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表