ansible-课程大纲

all

https://www.ansible.com/resources/whitepapers/ansible-in-depth
https://www.ansible.com/resources/whitepapers/benefits-of-agentless-architecture

https://www.ansible.com/resources/videos/quick-start-video
https://docs.ansible.com/

https://github.com/ansible/ansible/tree/devel/docs/docsite

https://www.ibm.com/developerworks/cn/linux/1608_lih_ansible/index.html

Ansible2.0 升级2.9指南

书籍
https://www.ansible.com/resources/ebooks?extIdCarryOver=true&sc_cid=701f2000001OH6uAAG


https://docs.ansible.com/ansible/2.9/modules/user_module.html
https://docs.ansible.com/ansible/2.9/modules/
https://docs.ansible.com/ansible/2.9/modules/list_of_commands_modules.html

  • 基础
    • 超快速上手
    • 概念理论(做PPT标配)
    • 生产环境安装 (普通安装,Running in a virtualenv)
    • 静态主机清单
      • 生产、测试、机房
      • 主机和组(hosts and groups)
      • 主机变量和组变量(host variables and group variables)
    • Ad-hoc commands
    • SSH连接配置
    • 命令行工具
    • Playbooks(剧本)
    • 模块(module)
    • 提高执行权限(become)
    • ansible and git
  • 高级
    • 角色
    • 模块
    • 动态主机清单
    • 变量分离
    • 插件
    • Using collections
    • 图形界面
    • 拉取模式 ansible pull
    • 部署服务到Docker
    • ansible and rocket chat 服务部署通知
    • ansible 性能调优
    • ansible 最佳实践
    • 版本升级
    • 敏感信息管理(Ansible Vault)
  • 实战
    • Ansible与其它相关工具对比
    • 生产环境使用Ansible规划
    • Ansible 常用模块 官方文档集合

超快速上手

安装、简单使用,快速看到效果,不过多解释细节

待解决问题

安装的时候epel源里,并没有显示多个版本
所谓环境"干净",尤其是系统里不能有太多pip安装的东西

如何很好的利用Ansible返回的JSON数据

ansible 获取IP地址

https://www.cnblogs.com/morse/p/14036236.html

[root@192-168-31-106 /data/ysansible]# cat test2.yml 
---
- hosts: all
  tasks:

    - name: ansible_default_ipv4['address']
      debug:
        msg: echo {{ ansible_default_ipv4['address'] }}

    - name: ansible_host
      debug:
        msg: echo {{ ansible_host }}

    - name: replace
      debug:
        msg: echo {{ ansible_host | regex_replace('\.', '-') }}

    - hostname:
        name: testname1

    - name: set hostname
      shell: hostnamectl set-hostname {{ ansible_host | regex_replace('\.', '-') }}

变量替换的时候需要加上双引号

ansible copy 文件失效

可能是忽略了 末尾的斜杠导致 https://www.cnblogs.com/hixiaowei/p/9068445.html

galaxy

https://galaxy.ansible.com/docs/using/installing.html#id4


Determining Where Roles Are Installed
$ ansible-galaxy install --roles-path ~/ansible-roles debops.apt

Listing Your Installed Roles
$ ansible-galaxy list


[root@192_168_31_106 /data/galaxy]# ansible-galaxy install geerlingguy.apache geerlingguy.mysql geerlingguy.php

- downloading role 'apache', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-apache/archive/3.1.4.tar.gz
- extracting geerlingguy.apache to /root/.ansible/roles/geerlingguy.apache
- geerlingguy.apache (3.1.4) was installed successfully
- downloading role 'mysql', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-mysql/archive/3.3.0.tar.gz
- extracting geerlingguy.mysql to /root/.ansible/roles/geerlingguy.mysql
- geerlingguy.mysql (3.3.0) was installed successfully
- downloading role 'php', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-php/archive/4.5.1.tar.gz
- extracting geerlingguy.php to /root/.ansible/roles/geerlingguy.php
- geerlingguy.php (4.5.1) was installed successfully
[root@192_168_31_106 /data/galaxy]# 
[root@192_168_31_106 /data/galaxy]# 
[root@192_168_31_106 /data/galaxy]# ls -l
total 0
[root@192_168_31_106 /data/galaxy]# 
[root@192_168_31_106 /data/galaxy]# ls -l
total 0
[root@192_168_31_106 /data/galaxy]# 
[root@192_168_31_106 /data/galaxy]# ls
[root@192_168_31_106 /data/galaxy]# ls /root/.ansible/roles
geerlingguy.apache  geerlingguy.mysql  geerlingguy.php

变量

roles/x/vars/main.yml 优先级比较高,比 roles/x/defaults/main.yml 里的高,一般不想让别人动动变量都放在 roles/x/vars/main.yml