samdoran / ansible-collection-macos

Ansible collection of roles and modules for use on macOS
7 stars 2 forks source link

xcode detection seems to be flawed under macOS 15 #38

Open webknjaz opened 2 weeks ago

webknjaz commented 2 weeks ago

Here's the log, I haven't yet attempted debugging so I'll just start a tracking issue FTR:

$ ansible-playbook guest.yml --ask-pass --ask-become-pass --limit=ansible-core-ci-template-macos-15.0-playground -vv
ansible-playbook [core 2.15.5]
  config file = ~/src/github/ansible/ansible-core-ci/parallels/deploy/ansible.cfg
  configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = ~/.pyenv/versions/3.11.4/envs/ansible-core-ci-pyenv-py3.11.4/lib/python3.11/site-packages/ansible
  ansible collection location = ~/.ansible/collections:/usr/share/ansible/collections
  executable location = ~/.pyenv/versions/ansible-core-ci-pyenv-py3.11.4/bin/ansible-playbook
  python version = 3.11.4 (main, Jul 18 2023, 13:30:02) [GCC 12.2.1 20230428] (~/.pyenv/versions/3.11.4/envs/ansible-core-ci-pyenv-py3.11.4/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
Using ~/src/github/ansible/ansible-core-ci/parallels/deploy/ansible.cfg as config file
[DEPRECATION WARNING]: DEFAULT_GATHER_SUBSET option, the module_defaults keyword is a more generic version and can apply to all calls to the 
M(ansible.builtin.gather_facts) or M(ansible.builtin.setup) actions, use module_defaults instead. This feature will be removed from ansible-core in version 
2.18. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
SSH password: 
BECOME password[defaults to SSH password]: 
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: guest.yml ******************************************************************************************************************************************
2 plays in guest.yml

PLAY [Install Xcode Command Lines Tools and system Python on macOS] ******************************************************************************************

TASK [samdoran.macos.command_line_tools : Check for Xcode Command Line Tools] ********************************************************************************
task path: ~/.ansible/collections/ansible_collections/samdoran/macos/roles/command_line_tools/tasks/bootstrap.yml:1
ok: [ansible-core-ci-template-macos-15.0-playground] => {"changed": false, "failed_when_result": false, "rc": 0, "stderr": "Shared connection to ansible-core-ci-template-macos-15.0-playground closed.\r\n", "stderr_lines": ["Shared connection to ansible-core-ci-template-macos-15.0-playground closed."], "stdout": "\r\n16777220 12884908127 drwxr-xr-x 3 root wheel 0 96 \"Jun  6 09:09:55 2024\" \"Jun  6 09:09:55 2024\" \"Jun 13 00:35:27 2024\" \"Jun  6 09:09:55 2024\" 4096 0 0 /Library/Developer/CommandLineTools\r\n", "stdout_lines": ["", "16777220 12884908127 drwxr-xr-x 3 root wheel 0 96 \"Jun  6 09:09:55 2024\" \"Jun  6 09:09:55 2024\" \"Jun 13 00:35:27 2024\" \"Jun  6 09:09:55 2024\" 4096 0 0 /Library/Developer/CommandLineTools"]}

TASK [samdoran.macos.command_line_tools : Create hidden install file] ****************************************************************************************
task path: ~/.ansible/collections/ansible_collections/samdoran/macos/roles/command_line_tools/tasks/bootstrap.yml:14
skipping: [ansible-core-ci-template-macos-15.0-playground] => {"changed": false, "false_condition": "xcode_cl_tools.rc", "skip_reason": "Conditional result was False"}

TASK [samdoran.macos.command_line_tools : List updates] ******************************************************************************************************
task path: ~/.ansible/collections/ansible_collections/samdoran/macos/roles/command_line_tools/tasks/bootstrap.yml:21
skipping: [ansible-core-ci-template-macos-15.0-playground] => {"changed": false, "false_condition": "xcode_cl_tools.rc", "skip_reason": "Conditional result was False"}

TASK [samdoran.macos.command_line_tools : Install Xcode Command Line Tools] **********************************************************************************
task path: ~/.ansible/collections/ansible_collections/samdoran/macos/roles/command_line_tools/tasks/bootstrap.yml:30
skipping: [ansible-core-ci-template-macos-15.0-playground] => {"changed": false, "false_condition": "xcode_cl_tools.rc", "skip_reason": "Conditional result was False"}

TASK [samdoran.macos.command_line_tools : Remove hidden install file] ****************************************************************************************
task path: ~/.ansible/collections/ansible_collections/samdoran/macos/roles/command_line_tools/tasks/bootstrap.yml:40
skipping: [ansible-core-ci-template-macos-15.0-playground] => {"changed": false, "false_condition": "xcode_cl_tools.rc", "skip_reason": "Conditional result was False"}

TASK [samdoran.macos.command_line_tools : Test default Python] ***********************************************************************************************
task path: ~/.ansible/collections/ansible_collections/samdoran/macos/roles/command_line_tools/tasks/bootstrap.yml:47
fatal: [ansible-core-ci-template-macos-15.0-playground]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "xcode-select: note: No developer tools were found, requesting install.\nIf developer tools are located at a non-default location on disk, use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, and cancel the installation dialog.\nSee `man xcode-select` for more details.\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}

PLAY RECAP ***************************************************************************************************************************************************
ansible-core-ci-template-macos-15.0-playground : ok=1    changed=0    unreachable=0    failed=1    skipped=4    rescued=0    ignored=0
webknjaz commented 2 weeks ago

The folder presence check in the VM reports that it exists which is why the role skips attempting to install it:

administrator@ansible-core-ci-template-macos-15 ~ % stat /Library/Developer/CommandLineTools
16777220 12884908127 drwxr-xr-x 3 root wheel 0 96 "Jun  6 09:09:55 2024" "Jun  6 09:09:55 2024" "Jun 13 00:35:27 2024" "Jun  6 09:09:55 2024" 4096 0 0 /Library/Developer/CommandLineTools

Looks like we need to come up with a better check.

webknjaz commented 2 weeks ago

By the way, I made an installer image of macOS 15 through this great tool https://github.com/ninxsoft/mist-cli.

webknjaz commented 2 weeks ago
administrator@ansible-core-ci-template-macos-15 ~ % ls -alh /Library/Developer/CommandLineTools
total 0
drwxr-xr-x  3 root  wheel    96B Jun  6 09:09 .
drwxr-xr-x  3 root  wheel    96B Jun  6 09:09 ..
-rw-r--r--  1 root  wheel     2B Jun  6 09:09 .beta
administrator@ansible-core-ci-template-macos-15 ~ % file /Library/Developer/CommandLineTools/.beta
/Library/Developer/CommandLineTools/.beta: ASCII text
administrator@ansible-core-ci-template-macos-15 ~ % cat /Library/Developer/CommandLineTools/.beta
1
webknjaz commented 2 weeks ago

I performed sudo mv /Library/Developer/CommandLineTools{,.bak} to work around the issue for now.

webknjaz commented 1 week ago

Looking at https://mac.install.guide/commandlinetools/2, I think that the pkgutil --pkg-info=com.apple.pkg.CLTools_Executables option is the most robust.

webknjaz commented 1 week ago

There's also some quirks, it seems: https://stackoverflow.com/a/75425459/595220

samdoran commented 1 week ago

By the way, I made an installer image of macOS 15 through this great tool

I was wondering how you got a macOS 15 installer so fast. That's a really neat tool.

samdoran commented 1 week ago

It looks like for the beta version the folder is created with that single hidden dot file. Maybe we could check for a file inside /Library/Developer/CommandLineTools/. That first article suggested looking for /Library/Developer/CommandLineTools/usr/bin/git, but we could probably use anything in there.

Changing _macos_cli_tools_dir to a sub dir is probably be the simplest fix. Might need to change that variable name as well to indicate the changed purpose.