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?

Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user

Posted at

Ansibleでbecome_user: postgresが失敗する問題と解決策(AlmaLinux 10)

概要

AlmaLinux OS 10の最小構成環境で、Ansibleを使ってPostgreSQLのinitdbを実行しようとしたところ、become_user: postgresのタスクでエラーが発生しました。

本記事ではその原因と、aclパッケージのインストールによる解決方法についてまとめます。

環境

  • OS: AlmaLinux OS 10 (最小構成)
  • Ansible: core 2.17.12
  • PostgreSQL: 17

問題のタスク

- name: initdb
  become: true
  become_user: postgres
  command: /usr/pgsql-17/bin/initdb -D /var/lib/pgsql/17/data --locale=C
  args:
    creates: /var/lib/pgsql/17/data/postgresql.conf

このタスクを実行すると、以下のようなエラーが発生します。

エラーメッセージ(整形済み)

fatal: [local_120]: FAILED!

Message:
  Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user.

Return Code:
  1

Error:
  chmod: 無効なモード: `A+user:postgres:rx:allow`

Hint:
  詳しくは 'chmod --help' を実行して下さい。

More Info:
  https://docs.ansible.com/ansible-core/2.17/playbook_guide/playbooks_privilege_escalation.html#risks-of-becoming-an-unprivileged-user

原因

「接続ユーザー(remote_user)」と「become_user」がどちらも非特権ユーザー(rootではない)である場合、モジュールファイルは「接続ユーザー」の権限で作成されますが、Ansibleはそれを「become_user」でも読み取れるようにしなければなりません。
POSIXシステムにおいてAnsibleはこの問題を以下の手順で解決しようとします。

  1. setfaclが使える場合(ACLが有効なファイルシステム)
    setfaclコマンドがPATHにあり、かつ一時ディレクトリがPOSIX ACLをサポートしていれば、ACLを使ってbecome_userにファイル読み取り権限を付与します。

以下略

AlmaLinux OS 10 (最小構成)ではsetfclが使えないため、エラーが発生しました。

解決方法

setfaclを利用可能にするため、acl パッケージをインストールします。

sudo dnf install -y acl

その後、再度Ansibleを実行すると、問題なくinitdbタスクが成功するようになりました。

まとめ

  • Ansibleで非特権ユーザーにbecome_userするときはACLが必要
  • AlmaLinux 10など最小構成ではaclが未インストールのため注意

参考

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?