大网数据广告活动
服务器运维问答

How do I make Ansible actually compile a config file having changed my debconf settings for an application?

· 52CE 我爱测

I'm using Ansible to try to configure all of the workstations involved with a particular project to be able to use BitTorrent sync with a standard configuration (this is actually just an example of the kind of thing I want to do)…

问题原文

原帖链接 · Salim Fadhley · CC BY-SA 3.0

I'm using Ansible to try to configure all of the workstations involved with a particular project to be able to use BitTorrent sync with a standard configuration (this is actually just an example of the kind of thing I want to do).

When I execute the playbook I can confirm that the debconf settings on the remote PCs have been updated, however the config file for the application has not been updated.

Is there a way to get ansible to finish the job off - having supplied a bunch of config data I just want to recompile the actual config file and then restart the service.

I'm using the latest Ansible (from PyPi) on Ubuntu 14.10 64bit hosts.

- hosts: btsync
  sudo: True
  tasks:
    - apt_repository: repo='ppa:tuxpoldo/btsync' update_cache=yes state=present
    - apt: name=btsync state=present
    - apt: name=debconf-utils state=present
    - apt: name=btsync-gui state=present
    - file: name='create a directory for BT Sync' path=/home/sal/bittorrent_sync state=directory owner=sal group=users mode=0755
    - debconf: name='btsync' question='btsync/runas' value='sal' vtype='string'
    - debconf: name='btsync' question='btsync/directory_root' value='/home/sal/bittorrent_sync' vtype='string'
    - debconf: name='btsync' question='btsync/webgui-bindaddr' value='0.0.0.0' vtype='string'
    - debconf: name='btsync' question='btsync/folder_defaults-use_lan_broadcast' value='true' vtype='boolean'
    - debconf: name='btsync' question='btsync/log_size' value='1' vtype='string'
    - debconf: name='btsync' question='btsync/folder_defaults-use_dht' value='true' vtype='boolean'
    - service: name='btsync' state=restarted

I can force the config file to be reconfigured from the debconf like this:

sudo dpkg-reconfigure -f noninteractive btsync

I suppose I could force Ansible to remotely execute that statement, but surely there's a better, more ansibleish way to do this?

已采纳解答

原帖链接 · xddsg · CC BY-SA 4.0

That's how debconf works, you wouldn't expect packages to reconfigure automatically if you just edited the file either.

What you want is a notify handler that does the dpkg reconfigure once at the end of the play.

- debconf:
  name: 'btsync'
  question: 'btsync/folder_defaults-use_dht'
  value: 'true'
  vtype: 'boolean'
notify: reconfigure btsync

and in your handlers file:

- name: reconfigure btsync
  command: sudo dpkg-reconfigure -f noninteractive btsync

Now, if debconf actually changed anything (and only if - idempotent), btsync will get reconfigured once when all your tasks have run.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-03-31)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。