大网数据广告活动
服务器运维问答

Ansible vs. custom made solution

· 52CE 我爱测

I have a pool of around a dozen workstations running Linux and I need a system to somehow keep them in sync (same software installed, same configuration, same users, ...) and also allow me to evolve them in time (think configurat…

问题原文

原帖链接 · Liviu · CC BY-SA 4.0

I have a pool of around a dozen workstations running Linux and I need a system to somehow keep them in sync (same software installed, same configuration, same users, ...) and also allow me to evolve them in time (think configuration changes, driver updates, new software...). The trick is that sometimes, some of them are taken offline and are only reactivated after weeks, even months and sometimes new workstations are added and need to be configured from scratch.

I was looking into using Ansible and it seems great, but for my use case it has two disadvantages:

  • it does not have an auto-update feature (when a box is booted after a long period of inactivity I need to manually run the playbook on the controller station)
  • after years in production the playbook would get really long. Having to run it on a workstation that only missed a few updates would be very inefficient. Even if all tasks are idempotent, each of them would have to be sent to the workstation just to see if it was executed or not. Splitting the playbook into smaller parts is not ideal either as it would require to keep track of what was executed and where.

The alternative I'm thinking of is to have a repository of scripts and use GNU Make to run them. Make is used to update targets from sources, it basically runs a command on a source file to produce an output (e.g. compile a C program into a binary). If I treat scripts as sources then a Makefile like this would do the job:

TASKS= \
    install_apps \
    start_services \
    add_users

TARGETS=$(TASKS:=.done)

all: $(TARGETS)

%.done: %.sh
    echo "running $<"
    ./$<
    touch $@

When one of the workstations boots, it could automatically pull the script repo and run make. With this system in place, the tasks are run only once and in the order they are listed.

Questions

  • Do you think the disadvantages I listed are false? Maybe there is a way/workaround to achieve my goal using Ansible
  • Do you see any problems with the alternative I proposed? Bare in mind that the above Makefile is simplified and is not production ready.

已采纳解答

原帖链接 · Henrik Pingel · CC BY-SA 4.0

The first disadvantage, Ansible being a push based system, can be mitigated by using ansible-pull. ansible-pull

pulls playbooks from a VCS repo and executes them for the local host

ansible-pull could be triggered by cron or a startup script.

The second disadvantage of long running playbooks is sort of true. Ansible is not the fastest configuration management system on the market. However Ansible execution time can be reduced using mitogen and it is relatively easy to implement conditionals to skip parts of a playbook in order to speed up the play like this:

  - name: Register a variable
    ansible.builtin.shell: cat /etc/motd
    register: motd_contents

  - name: Use the variable in conditional statement to run long running play
    include: otherplays.yaml
    when: motd_contents.stdout.find('hi') != -1

If you write playbooks with execution time in mind it can be as fast as plain bash.

In general Ansible provides a lot of helpful tools to configure systems. There is probably nothing in Ansible which couldn't be implemented using something like Make and Bash. The advantage of Ansible over Bash is that a lot of people find it easier to work with and the code more readable.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-10-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。