0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Ansible] packageモジュールを利用する際のLinuxディストリビューション違いに伴うパッケージ名の差異問題を回避してみる

Posted at

Ansibleのpackageモジュール、ディストリビューションに依存しないパッケージインストールが可能になるが、ディストリビューション違いに伴うパッケージ名の差異は吸収してくれないので回避策を考えてみる

    - name: install virtualenv
      ansible.builtin.package:
        name: "{{ virtualenv_pkg_name[ansible_distribution] }}"
        state: present
      vars:
        virtualenv_pkg_name:
          CentOS: python-virtualenv
          Ubuntu: python3-virtualenv
  • set_fact でansible_distribution を取得
  • ansible_distributionの値がKeyになるように辞書を作成
  • 辞書のキー指定に変数を利用してディストリビューションによって返す値が変えられるようになる
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?