Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration files are not in json format #572

Open
zet694 opened this issue Nov 9, 2023 · 3 comments
Open

Configuration files are not in json format #572

zet694 opened this issue Nov 9, 2023 · 3 comments

Comments

@zet694
Copy link

zet694 commented Nov 9, 2023

Hi! When I use the default templates they come out in str format and not json as I expect, why can this happen?

root@consul-0:~# jq . /etc/consul/bootstrap.json 

"{'datacenter': 'dev', 'domain': 'consul', 'performance': {'raft_multiplier': 1, 'leave_drain_time': '5s', 'rpc_hold_timeout': '7s'}, 'bind_addr': '10.1.32.31', 'advertise_addr': '10.1.32.31', 'advertise_addr_wan': '10.1.32.31', 'translate_wan_addrs': False, 'client_addr': '127.0.0.1', 'addresses': {'dns': '127.0.0.1', 'http': '127.0.0.1', 'https': '127.0.0.1', 'grpc': '127.0.0.1', 'grpc_tls': '127.0.0.1'}, 'ports': {'dns': 8600, 'http': 8500, 'https': -1, 'serf_lan': 8301, 'serf_wan': 8302, 'server': 8300, 'grpc': -1, 'grpc_tls': -1}, 'raft_protocol': 3, 'data_dir': '/opt/consul', 'log_level': 'INFO', 'log_file': '/var/log/consul/consul.log', 'log_rotate_bytes': 0, 'log_rotate_duration': '24h', 'log_rotate_max_files': 0, 'disable_update_check': False, 'enable_script_checks': False, 'enable_local_script_checks': False, 'encrypt': 'nJr7+QmTlKyksbo1qiJFmCC2bQ4VCyAMjp2RQ33osYk=', 'encrypt_verify_incoming': True, 'encrypt_verify_outgoing': True, 'retry_interval': '30s', 'retry_max': 0, 'retry_join': ['10.1.32.31'], 'server': True, 'bootstrap': True, 'retry_interval_wan': '30s', 'retry_max_wan': 0, 'primary_datacenter': 'dev', 'acl': {'enabled': True, 'default_policy': 'allow', 'down_policy': 'extend-cache', 'token_ttl': '30s', 'enable_token_persistence': True, 'tokens': {'initial_management': '80d58de9-c559-5482-b251-ab7f66ca6591', 'replication': '8b65e0c6-fd42-531b-aab0-a3c4131f4714'}}, 'ui_config': {'enabled': True}}"

This is the case with all files in which the template is used (consul.json, server.json, bootstrap.json etc).

Ansible version:

❯ ansible --version

ansible [core 2.13.12]
  config file = /Users/zet694/Zdravcity/infra/ansible/ansible.cfg
  configured module search path = ['/Users/zet694/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/zet694/.zdravcity/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/zet694/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/zet694/.zdravcity/bin/ansible
  python version = 3.9.6 (default, Aug 11 2023, 19:44:49) [Clang 15.0.0 (clang-1500.0.40.1)]
  jinja version = 3.0.3
  libyaml = True

My variables:

---
consul_group_name: "_consul"
consul_zip_url: "https://blabla/common-infra/consul_1.16.3_linux_amd64.zip"
consul_checksum_file_url: "https://blabla/common-infra/consul_1.16.3_SHA256SUMS"
consul_version: "1.16.3"
consul_acl_enable: true
consul_acl_master_token_display: true
consul_acl_master_token: "$MY_TOKEN"
consul_debug: true
consul_datacenter: "{{ environment_name }}"
consul_encrypt_enable: true
@nre-ableton
Copy link
Contributor

When I examine such files, they are valid JSON. I suspect something else is going wrong here. Can you please paste the literal contents of said JSON files from your hosts after running this role?

@matutter
Copy link

matutter commented Mar 14, 2024

@nre-ableton I just ran into this this morning. The problem is here. https://github.com/ansible-collections/ansible-consul/blob/master/templates/config.json.j2#L37 when these options are used...

vars:
    consul_tls_enable: false
    consul_dnsmasq_enable: false

I changed ...

        {% if consul_version is version_compare('1.14.0', '>=') %}
        "grpc_tls": "{{ consul_addresses.grpc_tls }}",
        {% endif %}

to

        {% if consul_version is version_compare('1.14.0', '>=') and consul_tls_enable %}
        "grpc_tls": "{{ consul_addresses.grpc_tls }}",
        {% endif %}

To work around the problem.

[edit] maybe this isn't the same problem but the issue search took me here :)

@nre-ableton
Copy link
Contributor

@matutter Very nice, that makes sense. Would you be so kind as to submit a PR? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants