Dock not handling case where item is missing
maverickames opened this issue · 2 comments
When the dock does not have an item it fails to add. I found that when the item is missing it seems to try and got straight to moving the item instead of adding it. Output off the log.
TLDR:
TASK [geerlingguy.mac.dock : Get current dock item position from output.]
dockutil --find 'Mail
STDOUT: Mail was not found in /Users/username/Library/Preferences/com.apple.dock.plist
TASK [geerlingguy.mac.dock : Move dock item to the correct position.]
STDOUT: move failed for Mail in /Users/username/Library/Preferences/com.apple.dock.plist
MacOS: 11.6.1
ansible [core 2.11.6]
config file = /Users/username/ansible/ansible.cfg
configured module search path = ['/Users/username/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/username/.pyenv/versions/3.9.2/lib/python3.9/site-packages/ansible
ansible collection location = /Users/username/.ansible/collections:/usr/share/ansible/collections
executable location = /Users/username/.pyenv/versions/3.9.2/bin/ansible
python version = 3.9.2 (default, Nov 4 2021, 23:53:24) [Clang 13.0.0 (clang-1300.0.29.3)]
jinja version = 3.0.2
libyaml = True
TASK [geerlingguy.mac.dock : Check the current Dock position of Mail.] ***********************************************************************************************************************************************************************
task path: /Users/username/.ansible/collections/ansible_collections/geerlingguy/mac/roles/dock/tasks/dock-position.yml:2
ESTABLISH LOCAL CONNECTION FOR USER: username
EXEC /bin/sh -c 'echo ~username && sleep 0'
EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /Users/username/.ansible/tmp
"&& mkdir "echo /Users/username/.ansible/tmp/ansible-tmp-1636407351.824186-90626-81515475488421
" && echo ansible-tmp-1636407351.824186-90626-81515475488421="echo /Users/username/.ansible/tmp/ansible-tmp-1636407351.824186-90626-81515475488421
" ) && sleep 0'
Using module file /Users/username/.pyenv/versions/3.9.2/lib/python3.9/site-packages/ansible/modules/command.py
PUT /Users/username/.ansible/tmp/ansible-local-89678rvfa9hbb/tmpgjry2qpe TO /Users/username/.ansible/tmp/ansible-tmp-1636407351.824186-90626-81515475488421/AnsiballZ_command.py
EXEC /bin/sh -c 'chmod u+x /Users/username/.ansible/tmp/ansible-tmp-1636407351.824186-90626-81515475488421/ /Users/username/.ansible/tmp/ansible-tmp-1636407351.824186-90626-81515475488421/AnsiballZ_command.py && sleep 0'
EXEC /bin/sh -c '/usr/local/bin/python3 /Users/username/.ansible/tmp/ansible-tmp-1636407351.824186-90626-81515475488421/AnsiballZ_command.py && sleep 0'
EXEC /bin/sh -c 'rm -f -r /Users/username/.ansible/tmp/ansible-tmp-1636407351.824186-90626-81515475488421/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
"changed": false,
"cmd": [
"dockutil",
"--find",
"Mail"
],
"delta": "0:00:00.142636",
"end": "2021-11-08 13:35:52.151640",
"failed_when_result": false,
"invocation": {
"module_args": {
"_raw_params": "dockutil --find 'Mail'",
"_uses_shell": false,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": false
}
},
"rc": 1,
"start": "2021-11-08 13:35:52.009004"
}
STDOUT:
Mail was not found in /Users/username/Library/Preferences/com.apple.dock.plist
MSG:
non-zero return code
Read vars_file 'vars.yml'
TASK [geerlingguy.mac.dock : Get current dock item position from output.] ********************************************************************************************************************************************************************
task path: /Users/username/.ansible/collections/ansible_collections/geerlingguy/mac/roles/dock/tasks/dock-position.yml:9
ok: [localhost] => {
"ansible_facts": {
"current_position": {
"changed": false,
"cmd": [
"dockutil",
"--find",
"Mail"
],
"delta": "0:00:00.142636",
"end": "2021-11-08 13:35:52.151640",
"failed": false,
"failed_when_result": false,
"msg": "non-zero return code",
"rc": 1,
"start": "2021-11-08 13:35:52.009004",
"stderr": "",
"stderr_lines": [],
"stdout": "Mail was not found in /Users/username/Library/Preferences/com.apple.dock.plist",
"stdout_lines": [
"Mail was not found in /Users/username/Library/Preferences/com.apple.dock.plist"
]
}
},
"changed": false
}
Read vars_file 'vars.yml'
TASK [geerlingguy.mac.dock : Move dock item to the correct position.] ************************************************************************************************************************************************************************
task path: /Users/username/.ansible/collections/ansible_collections/geerlingguy/mac/roles/dock/tasks/dock-position.yml:13
ESTABLISH LOCAL CONNECTION FOR USER: username
EXEC /bin/sh -c 'echo ~username && sleep 0'
EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /Users/username/.ansible/tmp
"&& mkdir "echo /Users/username/.ansible/tmp/ansible-tmp-1636407352.247047-90653-10738341274533
" && echo ansible-tmp-1636407352.247047-90653-10738341274533="echo /Users/username/.ansible/tmp/ansible-tmp-1636407352.247047-90653-10738341274533
" ) && sleep 0'
Using module file /Users/username/.pyenv/versions/3.9.2/lib/python3.9/site-packages/ansible/modules/command.py
PUT /Users/username/.ansible/tmp/ansible-local-89678rvfa9hbb/tmp0gcuhy9c TO /Users/username/.ansible/tmp/ansible-tmp-1636407352.247047-90653-10738341274533/AnsiballZ_command.py
EXEC /bin/sh -c 'chmod u+x /Users/username/.ansible/tmp/ansible-tmp-1636407352.247047-90653-10738341274533/ /Users/username/.ansible/tmp/ansible-tmp-1636407352.247047-90653-10738341274533/AnsiballZ_command.py && sleep 0'
EXEC /bin/sh -c '/usr/local/bin/python3 /Users/username/.ansible/tmp/ansible-tmp-1636407352.247047-90653-10738341274533/AnsiballZ_command.py && sleep 0'
EXEC /bin/sh -c 'rm -f -r /Users/username/.ansible/tmp/ansible-tmp-1636407352.247047-90653-10738341274533/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {
"changed": true,
"cmd": [
"dockutil",
"--move",
"Mail",
"--position",
"2",
"-v"
],
"delta": "0:00:00.124462",
"end": "2021-11-08 13:35:52.529944",
"invocation": {
"module_args": {
"_raw_params": "dockutil --move 'Mail' --position '2' -v",
"_uses_shell": false,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": false
}
},
"rc": 0,
"start": "2021-11-08 13:35:52.405482"
}
STDOUT:
verbose: ('processing', '/Users/username/Library/Preferences/com.apple.dock.plist')
verbose: ('no match for', 'Safari')
verbose: ('no match for', 'Calendar')
verbose: ('no match for', 'System Preferences')
verbose: ('no match for', 'Visual Studio Code')
verbose: ('no match for', 'Launchpad')
move failed for Mail in /Users/username/Library/Preferences/com.apple.dock.plist
Read vars_file 'vars.yml'
After a bit more research I found that it looks like there are a few variables to how this works.
App Open but not set to 'Keep in Dock'
App not in dock and not open.
App in dock but in wrong position.
It also behaves different depending on if --ask-become-pass is passed.
I have everything working for adding now and am working a small PR but it prob needs reworked as I have only had a few hours with Ansible.
The one part I am still seeing issues with is moving. It passes everything correctly just never moves anything. If I run the same command I works right away. Like its a users space or run as user issue.
After further research I found that most of the issues I was seeing was because the constant restart of the dock. After looking into it a bit I made some changes to add --no-restart to the dockutil command so that it would not restart for each change. At the end I added a restart. Here is my pull request. geerlingguy/ansible-collection-mac#26