cmacrae.common

常见

一个 Ansible 角色,用于以灵活的方式管理各种类型的数据/资源/构造。

当前可管理的资源

  • 用户
  • 群组
  • Cron 任务
  • 软件包
  • 文件
  • 远程文件(从 URL 获取)
  • 文件中的行
  • sudo 配置
  • 软件包仓库(目前为 Yum,更多内容将会更新!)
  • Postgres 数据库、用户、扩展、语言

要求

Ansible >= 2.0.0

变量

名称 默认值 描述
common_users 未定义 一组需要管理的杂项用户字典(支持user模块的所有参数)
common_groups 未定义 一组需要管理的杂项组字典(支持group模块的所有参数)
common_cron_jobs 未定义 一组需要管理的杂项 Cron 任务字典(支持cron模块的所有参数)
common_packages 未定义 一组需要安装的杂项软件包列表
common_pips 未定义 一组通过 pip 安装的杂项 Python 包列表
common_files 未定义 一组需要管理的杂项文件字典(支持file模块的所有参数)
common_fetch_files 未定义 一组需要从 URL 获取的杂项远程文件字典(支持get_url模块的所有参数)
common_file_lines 未定义 一组需要管理的文件行字典(支持lineinfile模块的所有参数)
common_sudoer_configs 未定义 一组需要管理的杂项 sudoers 规则字典
common_yumrepos 未定义 一组需要管理的 Yum 仓库字典
common_postgres_dbs 未定义 一组需要管理的 Postgres 数据库字典(支持postgresql_db模块的所有参数)
common_postgres_users 未定义 一组需要管理的 Postgres 用户字典(支持postgresql_users模块的所有参数)
common_postgres_extensions 未定义 一组需要管理的 Postgres 扩展字典(支持postgresql_ext模块的所有参数)
common_postgres_langs 未定义 一组需要管理的 Postgres 存储过程语言字典(支持postgresql_lang模块的所有参数)

示例定义

你可以在任意层级定义任何数据/资源/构造(host_varsgroup_vars、playbook vars、一个 vars 文件、依赖该角色的角色等)。

用户

common_users:
  some_user:
    group: mygroup
    generate_ssh_key: true
    ssh_key_comment: "这是一个示例用户的密钥对"
  some_other_user: {}

群组

common_groups:
  mygroup: {}
  my_other_group:
    gid: 9001
    system: true

Cron 任务

common_cron_jobs:
  '检查目录':
    minute: 0
    hour: '5,2'
    job: 'ls -alh > /dev/null'
    state: absent
  '一些旧任务':
    state: absent
  '开机自启任务':
    special_time: reboot
    job: '/path/to/some_scrupt.sh'
    state: absent
  '使用 cron 文件的任务':
    job: 'uptime &> /dev/null'
    cron_file: cron_example
    state: absent

软件包

common_packages:
  - mg
  - golang

Python 包(通过 pip

common_pips:
  - ansible
  - Jinja2

文件

common_files:
  /tmp/myfile:
    owner: some_user
    group: some_user
    mode: 0644
    src: /tmp/my_example_file
  /tmp/my_other_file:
    owner: some_user
    group: some_user
    mode: 0644
    content: >-
      这些内容将被插入到
      /tmp/my_other_file中。

远程文件(从 URL 获取)

common_fetch_files:
  git_fat:
    url: 'https://raw.githubusercontent.com/jedbrown/git-fat/master/git-fat'
    dest: '/usr/bin/git-fat'
    mode: 755 # (这里不能使用明确的模式)
    owner: root
    group: root

文件中的行

common_file_lines:
  /etc/hosts:
    regexp: '^127\.0\.0\.1'
    line: '127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4'
    owner: root
    group: root
    mode: 0644
  /etc/sudoers:
    state: absent
    regexp: "^%wheel"

sudo 配置

common_sudoer_configs:
  hubot_multi_sudo_rules:
    content:
      - 'hubot ALL=(root) NOPASSWD: /usr/bin/systemctl restart hubot-*'
      - 'hubot ALL=(root) NOPASSWD: /usr/bin/systemctl start hubot-*'
      - 'hubot ALL=(root) NOPASSWD: /usr/bin/systemctl status hubot-*'
      - 'hubot ALL=(root) NOPASSWD: /usr/bin/systemctl stop hubot-*'
  hubot_just_date_cmd:
    content:
      - 'hubot ALL=(root) NOPASSWD: /bin/date'

软件包仓库(更多内容将会更新!)

# 部署 Yum 仓库
common_yumrepos:
  RethinkDB:
    descr: RethinkDB
    baseurl: 'http://download.rethinkdb.com/centos/6/x86_64'
    gpgcheck: 0
    enabled: 1

Postgres 数据库

common_postgres_dbs:
  example_db:
    login_password: 5uP3r5ecr37
    owner: some_user
    template: example_template0

Postgres 用户

common_postgres_users:
  example_user:
    db: some_test_db
    encrypted: true
    login_password: 5uP3r5ecr37

Postgres 扩展

common_postgres_extensions:
  example_extension:
    db: some_example_db

Postgres 语言

common_postgres_lang:
  example_lang:
    cascade: true
    db: example_db

许可证

MIT

作者信息

创建者:Calum MacRae

欢迎随时联系我 - @calumacraemailto:[email protected]
报告问题
贡献代码

关于项目

An ansible role to manage miscellaneous types of data/resources/constructs in an ad-hoc fashion.

安装
ansible-galaxy install cmacrae.common
许可证
Unknown
下载
426
拥有者