Ansible 的爭論

前幾天在 Hacker News Daily 上看到「Five Ansible Techniques I Wish I’d Known Earlier」這篇,裡面提到了一些 Ansible 的用法還蠻有用的,算是開始用 Ansible 後應該都會有幫助的用法... 不過 Hacker News 上的討論「Ansible Techniques I Wish I’d Known Earlier (zwischenzugs.com)」比較精彩...

目前在頂端的留言對 Ansible 幹到不行,尤其是那個 YAML 格式:

Ansible is abysmal. I don't know why anyone still chooses it. It's a mess of yaml and what feels like a million yaml files that is always extremely hard to follow. Honestly writing some python, or bash is a lot easier to follow, read, and understand. The only thing it has going for it is the inventory system. I wish ansible would die already.

然後講到 bash 與 python 之類的工具時有人提到 idempotent:

>bash and python
Neither of those of idempotent.

馬上就有人幹勦,大多數人在寫 Ansible playbook 時根本沒人在注意 idempotent,而且一堆 shell script 的東西被塞進 YAML 只能說痛苦 XDDD

Most of the ansible roles I come across written by my team are not idempotent either, its a huge lie that Ansible is idempotent. Its idempotent if you put the effort into make it be but if I see tons of shell or command module invocations without prerequisite checks to see if the work should be done. Most devs I see using Ansible treat it like a shell script written in YAML and to that purpose it sucks.

我自己目前會挑 Ansible 主要還是因為 server 不需要另外裝軟體,是個 production 為導向的設計,再更大的時候就要想一下要怎麼繼續搞下去了...

自己架設各種服務的 ansible playbook:Sovereign

來清個瀏覽器上的 tab,sovereign 是個 ansible playbook,幫你架設各種服務:

Sovereign is a set of Ansible playbooks that you can use to build and maintain your own personal cloud based entirely on open source software, so you’re in control.

裡面包了許多服務,但看下來比較麻煩的是郵件相關的服務,現在要自己搞一整包郵件系統一直都是痛點,這點在 Hacker News 上偶而就會看到分享...

這包 ansible playbook 裡面跟郵件相關的部份包括了 PostfixDovecot 搭出基本的 SMTP + IMAP + POP3,另外用 Solr (全文搜尋)、PostgreSQL (Virtual domain)、Rspamd (擋 spam),DKIMDMARC (郵件來源認證機制),以及 Roundcube (Webmail)。

非郵件相關的話包括了 VPN、cloud storage,以及一些管理、安全、備份有關的服務可以用,看起來的確是把常用的東西都放進去了。

不過這種東西自己架是有自己架的「樂趣」,而且對底層掌握度也比較高 (尤其是又有隱私與安全性的考量),對應的客群應該會看一看架構,然後自己動手?

YAML 裡放多行區塊的方式

因為在寫 ansible 的 playbook,有些地方想要偷懶,把檔案放進在 playbook 本身...

網路上搜了一下找到「In YAML, how do I break a string over multiple lines?」這篇,最常用的應該是 ||- 以及 |+ 了,用這三招塞檔案應該是夠用...

裡面的範例拿 JSON 的格式來解釋還蠻有趣的,代表 JSON 真的很好懂...

SaltStack 與 Ansible 的比較

也忘記在哪邊看到的,反正是留在 browser 上的連結。

puppet 跳槽,因為 SaltStack (Salt) 與 Ansible 都是使用 Python 而被選擇,然後完整比較後記錄下來:「Moving away from Puppet: SaltStack or Ansible?」。

先說結論,最後看起來是選擇了 Salt:

At this point both Salt and Ansible are viable and excellent options for replacing Puppet. As you may have guessed by now, I’m more in favor of Salt.

作者花了相當多的時間比較得到結論,包括從 puppet porting 一個完整的部份 (不是全部,不過還是為數可觀的部份),以及 porting 中間發現問題後開 ticket 詢問。除了技術面上的評估外,還包括了 community 的態度... (其實是狂婊 Ansible... XDDD)