LoginSignup
8
7

More than 5 years have passed since last update.

Ansible でリモートのアーキテクチャに応じて挙動を変える

Posted at

たとえば,RPM パッケージを持っていってインストールしたい場合,アーキテクチャによって RPM が変わりますよね (i686 とか x86_64 とか)。

そんなときは,ansible_machine という variable を使えば,リモートのアーキテクチャを特定することができます。

---
tasks:
  - copy: src="custom.{{ansible_machine}}.rpm" dest="/tmp/custom.rpm"

ちなみに Linux の場合,

Variable 32bit 64bit
ansible_architecture i386 x86_64
ansible_machine i686 x86_64
ansible_userspace_architecture i386 x86_64
ansible_userspace_bits 32 64

こんな感じになるようです。

これらの variables は,setup module を使うと確認できます。

$ ansible host -m setup

アーキテクチャ以外にもいろいろ定義されている (distribution とか IP アドレスとか) ので,ほかにも条件わけするのによい variable があるかもしれません。

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7