I have Bitwarden set up to be accessed through a reverse proxy that is on another VM (multiple hosts via one public IP); this setup requires real_ips in Bitwarden's config.yml. This is presenting a challenge.
The bitwarden role writes the config in flow style:
real_ips: ['192.168.12.34']
When bitwarden.sh rebuild is run, the rebuild rewrites this to a block sequence:
real_ips:
- 192.168.12.34
If the tasks in configure.yml run again, the result is invalid yaml, which Bitwarden rejects:
real_ips: ['192.168.12.34']
- 192.168.12.34
One possible solution is to change the lineinfile module to replace. This prevents malformed yaml by matching all the lines in the block sequence. This approach would automatically handle any future sequence field and could be extended for mapping types, but it is not quite idempotent and an extra bitwarden.sh rebuild occurs.
- name: Ensure custom values in Bitwarden configuration
ansible.builtin.replace:
path: "{{ bitwarden_install_dir }}/config.yml"
regexp: "^{{ item.key }}:.*(\n *-.*)*"
replace: "{{ item.key }}: {{ item.value }}"
loop: "{{ bitwarden_setup_config | dict2items }}"
register: bw_config
notify: rebuild bitwarden
Another approach would be to define a variable (bitwarden_real_ips) and write that out as a block sequence (e.g. using blockinfile and the to_nice_yaml filter).
What do you think? I'd be happy to provide either alternative as a PR, or something else if you'd prefer.
I have Bitwarden set up to be accessed through a reverse proxy that is on another VM (multiple hosts via one public IP); this setup requires
real_ipsin Bitwarden'sconfig.yml. This is presenting a challenge.The bitwarden role writes the config in flow style:
When
bitwarden.sh rebuildis run, the rebuild rewrites this to a block sequence:If the tasks in
configure.ymlrun again, the result is invalid yaml, which Bitwarden rejects:One possible solution is to change the
lineinfilemodule toreplace. This prevents malformed yaml by matching all the lines in the block sequence. This approach would automatically handle any future sequence field and could be extended for mapping types, but it is not quite idempotent and an extrabitwarden.sh rebuildoccurs.Another approach would be to define a variable (
bitwarden_real_ips) and write that out as a block sequence (e.g. usingblockinfileand theto_nice_yamlfilter).What do you think? I'd be happy to provide either alternative as a PR, or something else if you'd prefer.