ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
193 stars 152 forks source link

improper string handling (evaluation) in community.windows.win_timezone #545

Open europ opened 7 months ago

europ commented 7 months ago
SUMMARY

Improper string handling (evaluation) in community.windows.win_timezone.

A string that includes white spaces is split apart and the extracted first field (field separator is white space) only is used.

ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
$ ansible --version

ansible [core 2.16.1]
  config file = /mnt/ansible/ansible.cfg
  configured module search path = ['/home/****/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
  ansible collection location = /home/****/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.5 (main, Nov 15 2023, 18:13:17) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20.0.1)] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
$ ansible-galaxy collection list

# /home/***/.ansible/collections/ansible_collections
Collection           Version
-------------------- -------
community.windows    2.1.0
CONFIGURATION
$ ansible-config dump --only-changed

CONFIG_FILE() = /mnt/ansible/ansible.cfg
DEFAULT_ROLES_PATH(/mnt/ansible/ansible.cfg) = ['/mnt/ansible/roles']
INVENTORY_IGNORE_EXTS(/mnt/ansible/ansible.cfg) = ["{{(REJECT_EXTS + ('.orig'", '.cfg', "'.retry'))}}"]
OS / ENVIRONMENT
STEPS TO REPRODUCE
  1. add Windows host to inventory (e.g. Windows Server 2022)
  2. set ansible_shell_type=powershell for the host
  3. create a task in playbook that uses win_timezone with extra variable
    - name: configure timezone
      community.windows.win_timezone:
        timezone: '{{ timezone }}'
  4. run playbook
    ansible-playbook -i ./inventory ./playbook.yml -e timezone='Pacific Standard Time' -vvv
EXPECTED RESULTS
changed: [1.1.1.1] => {
    "changed": true,
    "previous_timezone": "UTC",
    "timezone": "Pacific Standard Time"
}
ACTUAL RESULTS
fatal: [1.1.1.1]: FAILED! => {
    "changed": false,
    "msg": "The specified timezone: Pacific isn't supported on the machine.",
    "previous_timezone": "UTC",
    "timezone": "Pacific"
}
WORKAROUND

Using single quotation marks within double quotation marks solves the problem.

ansible-playbook -i ./inventory ./playbook.yml -e timezone="'Pacific Standard Time'" -vvv