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
    - 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='' 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?


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.

| improve this answer | |
  • 1
    How do you get the list of questions from the package? – naisanza Sep 16 '17 at 3:01
  • 3
    @naisanza, use debconf-show PACKAGE – Gheesh Jan 21 '18 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.