问题原文
原帖链接 · 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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
