Xcode license issue, need to accept the license to accept the license

62 Views Asked by At

I'm trying to setup a couple Mac instances on AWS. To do this, I configure a custom AMI using Packer and ansible. One of my configurations is installing Xcode, which I do with these tasks:

- name: Remove existing Xcode.app
  file:
    path: "/Applications/Xcode.app"
    state: absent
  become: true
  tags:
    - xcode

- name: Remove existing Xcode-beta.app
  file:
    path: "/Applications/Xcode-beta.app"
    state: absent
  become: true
  tags:
    - xcode

- name: Check Xcode XIP exists
  stat:
    path: "{{ xcode_xip_path }}"
  register: "xcode_xip_check"
  changed_when: false
  tags:
    - xcode

- name: Download Xcode XIP file from aws s3 bucket
  shell: /usr/local/bin/aws s3 cp s3://{{ aws_s3_bucket_name }}/{{ xcode_xip_name }} {{ xcode_xip_path }} --no-progress
  when: not xcode_xip_check.stat.exists
  tags:
    - xcode

- name: Extract {{ xcode_xip_name }}
  command: xip -x {{ xcode_xip_path }}
  args:
    chdir: /Applications
  tags:
    - xcode

- name: Accept license
  shell: "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -license accept"
  become: true
  tags:
    - xcode

- name: Switch dev tools to Xcode
  command: xcode-select --switch /Applications/Xcode.app/Contents/Developer
  become: true
  tags:
    - xcode

- name: Validate xcode
  command: "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -runFirstLaunch"
  become: true
  tags:
    - xcode
    
- name: Activate developer mode
  command: /usr/sbin/DevToolsSecurity -enable
  become: true
  tags:
    - xcode

- name: Install Additional Components MobileDevice
  command: installer -pkg MobileDevice.pkg -target /
  become: true
  args:
    chdir: /Applications/Xcode.app/Contents/Resources/Packages/
  tags:
    - xcode

- name: Install Additional Components MobileDeviceDevelopment
  command: installer -pkg MobileDeviceDevelopment.pkg -target /
  become: true
  args:
    chdir: /Applications/Xcode.app/Contents/Resources/Packages/
  tags:
    - xcode

- name: Install Additional Components XcodeSystemResources
  command: installer -pkg XcodeSystemResources.pkg -target /
  become: true
  args:
    chdir: /Applications/Xcode.app/Contents/Resources/Packages/
  tags:
    - xcode
    
- name: Remove installer {{ xcode_xip_path }}
  file:
    path: "{{ xcode_xip_path }}"
    state: absent
  tags:
    - xcode

Problem is, when running ansible, it fails at Accept license task:

    amazon-ebs.mac-packer-aws: TASK [Accept license]    **************************************
    amazon-ebs.mac-packer-aws: task path: /var/lib/ansible-playbook/tasks/xcode-install.yml:39
    amazon-ebs.mac-packer-aws: fatal: [127.0.0.1]: FAILED! => {
    amazon-ebs.mac-packer-aws:     "changed": false,
    amazon-ebs.mac-packer-aws:     "module_stderr": "You have not agreed to the Xcode license agreements. Please run 'sudo xcodebuild -license' from within a Terminal window to review and agree to the Xcode and Apple SDKs license.\n",
    amazon-ebs.mac-packer-aws:     "module_stdout": "",
    amazon-ebs.mac-packer-aws:     "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    amazon-ebs.mac-packer-aws:     "rc": 69
    amazon-ebs.mac-packer-aws: }

It seems like I need to accept the license to accept the license itself... I can't move past this. I've tried change the Accept license task around, as I originally had it after the Switch dev tools to Xcode and Validate xcode tasks

Additional info: Source AMI: amzn-ec2-macos-14.3-20240208-211058 Xcode version: 15.3

I've tried a lot of different methods to install Xcode, none of them worked.

I've tried changing the order of the Accept license task, no success also.

0

There are 0 best solutions below