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

~ gets evaluated when using community.general.osx_defaults #5234

Closed
1 task done
pavelzw opened this issue Sep 4, 2022 · 5 comments · Fixed by #5243
Closed
1 task done

~ gets evaluated when using community.general.osx_defaults #5234

pavelzw opened this issue Sep 4, 2022 · 5 comments · Fixed by #5243
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type) system

Comments

@pavelzw
Copy link
Contributor

pavelzw commented Sep 4, 2022

Summary

When passing ~ as value to the community.general.osx_defaults plugin, it gets directly evaluated to /Users/pavelzwerschke.

This is probably because the value is not passed with quotes to the command line.

When doing it manually, we get the same problem:

$ defaults write com.googlecode.iterm2 PrefsCustomFolder ~/.config/iterm2
$ defaults read com.googlecode.iterm2 PrefsCustomFolder
/Users/pavelzwerschke/.config/iterm2

Instead, we want ansible to do something like this:

$ defaults write com.googlecode.iterm2 PrefsCustomFolder '~/.config/iterm2'
$ defaults read com.googlecode.iterm2 PrefsCustomFolder
~/.config/iterm2

Also, when executing the playbook twice, it still says changed instead of ok the second time because the string comparison is still evaluated to false.

Issue Type

Bug Report

Component Name

community.general.osx_defaults

Ansible Version

$ ansible --version
ansible [core 2.13.3]
  config file = /Users/pavelzwerschke/Projekte/ansible-provision/ansible.cfg
  configured module search path = ['/Users/pavelzwerschke/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Caskroom/mambaforge/base/envs/ansible/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/pavelzwerschke/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/Caskroom/mambaforge/base/envs/ansible/bin/ansible
  python version = 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:41:22) [Clang 13.0.1 ]
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /Users/pavelzwerschke/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 5.5.0

# /opt/homebrew/Caskroom/mambaforge/base/envs/ansible/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 5.5.0

Configuration

$ ansible-config dump --only-changed
DEFAULT_HOST_LIST(/Users/pavelzwerschke/Projekte/ansible-provision/ansible.cfg) = ['/Users/pavelzwerschke/Projekte/ansible-provision/inventory']

OS / Environment

macOS 12.5.1

Steps to Reproduce

---
- hosts: all
  tasks:
    - name: Ensure iTerm2 custom preferences location is set.
      community.general.osx_defaults:
        domain: com.googlecode.iterm2
        key: PrefsCustomFolder
        value: "~/.config/iterm2"
        type: string
        state: present

Expected Results

Expected:

$ defaults read com.googlecode.iterm2 PrefsCustomFolder
~/.config/iterm2

Actual Results

$ defaults read com.googlecode.iterm2 PrefsCustomFolder
/Users/pavelzwerschke/.config/iterm2

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) system labels Sep 4, 2022
@felixfontein
Copy link
Collaborator

The problem is that expand_user_and_vars=False needs to be passed to module.run_command() (https://github.com/ansible-collections/community.general/blob/main/plugins/modules/system/osx_defaults.py#L307). The default value for that flag is unfortunately True.

@pavelzw
Copy link
Contributor Author

pavelzw commented Sep 4, 2022

Would it break anything to set the flag to False there?

@felixfontein
Copy link
Collaborator

I think that should be ok. (Every change breaks something: https://xkcd.com/1172/)

pavelzw added a commit to pavelzw/community.general that referenced this issue Sep 6, 2022
pavelzw added a commit to pavelzw/community.general that referenced this issue Sep 6, 2022
felixfontein added a commit that referenced this issue Sep 10, 2022
* Add expand_user_and_vars flag to write

Closes #5234

* Add changelog

* Update changelogs/fragments/5243-osx-defaults-expand-user-flags.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
patchback bot pushed a commit that referenced this issue Sep 10, 2022
* Add expand_user_and_vars flag to write

Closes #5234

* Add changelog

* Update changelogs/fragments/5243-osx-defaults-expand-user-flags.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit f929422)
felixfontein pushed a commit that referenced this issue Sep 10, 2022
* Add expand_user_and_vars flag to write

Closes #5234

* Add changelog

* Update changelogs/fragments/5243-osx-defaults-expand-user-flags.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit f929422)

Co-authored-by: Pavel Zwerschke <pavelzw@gmail.com>
bratwurzt pushed a commit to bratwurzt/community.general that referenced this issue Nov 7, 2022
…ions#5243)

* Add expand_user_and_vars flag to write

Closes ansible-collections#5234

* Add changelog

* Update changelogs/fragments/5243-osx-defaults-expand-user-flags.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
bratwurzt pushed a commit to bratwurzt/community.general that referenced this issue Nov 7, 2022
…ions#5243)

* Add expand_user_and_vars flag to write

Closes ansible-collections#5234

* Add changelog

* Update changelogs/fragments/5243-osx-defaults-expand-user-flags.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This was referenced Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type) system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants