Add user to "administrators" group or "administrateurs" group

15 views
Skip to first unread message

fanchf...@gmail.com

unread,
Jul 10, 2017, 11:46:55 AM7/10/17
to Ansible Project
Hello,

I would like to create a playbook that adds a user to the administrators group. This action is simple and is an example. But my problem is that I have servers in FR and the group is not administrators but administrators.

I saw that you could make conditions in the playbooks but I do not know how to test if I am on an OS FR or US.

Could you advise me?

Thank you beforehand.

Regards

J Hawkesworth

unread,
Jul 10, 2017, 4:04:56 PM7/10/17
to Ansible Project

I suggest you run the 'setup' module against your hosts, and use one of the facts to find out if the machine is FS or US.

For windows hosts, ansible_facts.ansible_env.USERNAME might be enough.   If that isn't enough, on windows hosts you can use the Get-Culture cmdlet to find out which culture is current on your host.  Something like this.

- name: culture test
  hosts: 12,
  gather_facts: false
  tasks:
    - name: get culture
      win_shell: Get-Culture|select Name|convertto-json -depth 1
      register: culture_raw

    - name: debug culture_raw
      debug:
        var: culture_raw

    - name: set culture fact
      set_fact:
         culture: "{{culture_raw.stdout|from_json}}"

    - name: debug culture
      debug:
        var: culture

    - name: do things when culture is en-US
      debug:
        msg: Doing en-US things  
      when: culture.Name == 'en-US'

    - name: do things when culture is something else
      debug:
        msg: Doing non-en-US things  
      when: culture.Name != 'en-US'
Reply all
Reply to author
Forward
0 new messages