We don’t (yet) have the archives from the mailing-lists available to search over, so you’re working with a very fresh support site (it’s only been live for a week!). We’ll be able to fix that in the future, but for now search is not going to return much, indeed. Thanks for asking, it means the next person will find it in search
I’ve a role that does this for Debian, I’ve not tested it on Ubuntu but next time I do any work on it I’ll update the GitLab CI to run it using Molecule on several Debian versions and Ubuntu, it might work without adjustments!
Your playbook should work if you remove the LC_ALL=en_GB.UTF-8 from the last task, this is not actually related to Ansible itself, LC_ALL is not supported in the locale.conf file. Try:
- name: set as default locale
command: localectl set-locale LANG=en_GB.UTF-8
when: ansible_distribution == 'Ubuntu'
Using a role as stated above if you intend to do more complex set-ups is also a good idea!
You could use /etc/profile or the .bashrc file for LC_ALL.
thanks for your help thus far, I’m not sure about the ansible ‘role’ method, it’s currently a stretch too far for my ansible experience, I have not tackled ‘roles’ yet, though I’m sure in time I may be able to incorporate it.
I don’t like using ‘command’, as it kind of is obviating the use of ansible modules, but as it works, I’ll run with the proposed solution for the time being and I’ve confirmed the following works for my current config:-
These settings now result in the desired outputs:-
localectl
System Locale: LANG=en_GB.UTF-8
VC Keymap: gb
X11 Layout: gb
The VC Keymap eluded me for a while until I found a solution;
the way I was configuring those settings manually was with the command: dpkg-reconfigure …
Once again, I’ve marked your contributions as Solutions to my question, thanks for your help.
sorry may I appear to have gone ‘cold’ on this, but I’m currently off work sick.
I’ll run with it when I’m back at work in hopefully a couple of weeks.
pleased to say I’m back at work [have been for a couple of months, but with the backlog of work not had a chance to revisit ansible until now.]
I have attempted Chris’s solution, but unfortunately get the following error, but I’m unfamiliar with the constructs used, I’ve tried to get my head round them, but thought I’d paste the error here just i case someone rolls their eyes and goes, “yeah that’s because…!”:-
fatal: [ansiblemasterhost]: FAILED! => {“msg”: “The conditional check ‘locale_dcnf_locale != locale_lang and ansible_distribution == ‘Ubuntu’ and ansible_distribution_version == ‘22.04’’ failed. The error was: error while evaluating conditional (locale_dcnf_locale != locale_lang and ansible_distribution == ‘Ubuntu’ and ansible_distribution_version == ‘22.04’): ‘locale_lang’ is undefined. ‘locale_lang’ is undefined\n\nThe error appears to be in ‘/home/sisroot/ansible/ansiblescript.yml’: line 270, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Debconf set default locale Ubuntu 22\n ^ here\n”}
Here’s the relevant excerpt from my script:-
- name: Get existing debconf values for locales Ubuntu 22
ansible.builtin.debconf:
name: locales
register: locale_dcnf
- name: Set a variable for the current locales Ubuntu 22
ansible.builtin.set_fact:
locale_dcnf_locale: "{{ locale_dcnf | community.general.json_query(locale_dcnf_jpq) }}"
vars:
locale_dcnf_jpq: 'current.["locales/default_environment_locale"]|[0]'
when: ansible_distribution == 'Ubuntu' and ansible_distribution_version == '22.04'
- name: Debug existing debconf value for locales/default_environment_locale Ubuntu 22
ansible.builtin.debug:
var: locale_dcnf_locale
when: ansible_distribution == 'Ubuntu' and ansible_distribution_version == '22.04'
- name: Debconf set default locale Ubuntu 22
ansible.builtin.debconf:
name: locales
question: locales/default_environment_locale
value: "{{ locale_lang }}"
vtype: select
when: locale_dcnf_locale != locale_lang and ansible_distribution == 'Ubuntu' and ansible_distribution_version == '22.04'