LoginSignup
9
3

More than 3 years have passed since last update.

Ansibleでdnfコマンドを使う際の注意

Last updated at Posted at 2019-12-02

Ansible作成時に詰まったのでメモ。
2019/12/02現在の話。
環境はCentOS8、ansible2.9.1

dnf moduleコマンドがサポートされていない

まだサポートされていない模様。
参考:https://github.com/ansible/ansible/issues/64852

以下のようなコマンドがansibleのdnfだと現状使えない。
実行したい場合はcommandかshellで実行する。

ansible化したいコマンド
dnf module disable php
dnf module install php:remi-7.4
無理
# 以下のように書けない。
- name: php disable
  dnf:
    disable_repo: php

- name: php7.4 install
  dnf:
    name: php
    enable_repo: remi-7.4
こうやるしかない
- name: php disable
  shell: 'dnf module disable -y php'

- name: php7.4 install
  shell: 'dnf module install -y php:remi-7.4'

補足:

話はずれるが、php7.4を入れる場合はデフォルトでは入らないので
別途remiとepelリポジトリをインストールしておくこと。

- name: Install epel.repo
  dnf:
    name: 'https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm'
    state: present

- name: Install remi.repo
  dnf:
    name: 'https://rpms.remirepo.net/enterprise/remi-release-8.rpm'
    state: present

"@"が先頭に付くパッケージのインストール

バージョンまで指定しないとエラーになる

ダメな書き方
- name: mysql8 install
  dnf:
    name: '@mysql'
正しい書き方
- name: mysql8 install
  dnf:
    name: '@mysql:8.0'

まだまだ賢くはないらしい。

9
3
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
9
3