|
1 | 1 | --- |
2 | 2 | # Claude Code CLI installation and managed settings |
3 | 3 | # |
4 | | -# Installs Claude Code CLI and configures system-wide managed settings |
5 | | -# that apply to all users and cannot be overridden. |
| 4 | +# Linux: Native binary download with SHA256 verification from manifest |
| 5 | +# macOS: Homebrew cask |
6 | 6 | # |
| 7 | +# Binary location: ~/.local/bin/claude (installed by 'claude install') |
7 | 8 | # Settings location: /etc/claude-code/managed-settings.json (Linux) |
8 | 9 | # /Library/Application Support/ClaudeCode/managed-settings.json (macOS) |
9 | 10 |
|
10 | | -- name: Install Claude Code CLI globally for user (Linux) |
| 11 | +# ============================================================================ |
| 12 | +# Distribution URL |
| 13 | +# ============================================================================ |
| 14 | + |
| 15 | +- name: Set Claude Code distribution URL |
| 16 | + ansible.builtin.set_fact: |
| 17 | + claude_gcs_bucket: "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases" |
| 18 | + |
| 19 | +# ============================================================================ |
| 20 | +# Cleanup deprecated npm installation |
| 21 | +# ============================================================================ |
| 22 | + |
| 23 | +- name: Remove deprecated Claude Code npm package (Linux) |
11 | 24 | community.general.npm: |
12 | 25 | name: '@anthropic-ai/claude-code' |
13 | 26 | global: true |
14 | | - state: present |
| 27 | + state: absent |
15 | 28 | environment: |
16 | 29 | NPM_CONFIG_PREFIX: "{{ user_home }}/.npm-global" |
17 | 30 | become: false |
18 | 31 | become_user: "{{ actual_user }}" |
| 32 | + failed_when: false |
19 | 33 | when: ansible_facts['distribution'] in ['Fedora', 'Ubuntu'] |
20 | 34 |
|
21 | | -- name: Install Claude Code CLI globally for user (macOS) |
| 35 | +- name: Remove deprecated Claude Code npm package (macOS) |
22 | 36 | community.general.npm: |
23 | 37 | name: '@anthropic-ai/claude-code' |
24 | 38 | global: true |
25 | | - state: present |
| 39 | + state: absent |
26 | 40 | environment: "{{ npm_config_env }}" |
27 | 41 | become: false |
| 42 | + failed_when: false |
28 | 43 | when: ansible_facts['distribution'] == 'MacOSX' |
29 | 44 |
|
30 | | -- name: Enable Claude Code auto-update (Linux) |
31 | | - ansible.builtin.command: |
32 | | - cmd: "{{ user_home }}/.npm-global/bin/claude config set auto_update true" |
33 | | - become: false |
34 | | - become_user: "{{ actual_user }}" |
35 | | - failed_when: false |
36 | | - changed_when: false |
| 45 | +# ============================================================================ |
| 46 | +# Linux - Native binary installation with SHA256 verification |
| 47 | +# ============================================================================ |
| 48 | + |
| 49 | +- name: Install Claude Code native binary (Linux) |
| 50 | + block: |
| 51 | + - name: Fetch latest Claude Code version |
| 52 | + ansible.builtin.uri: |
| 53 | + url: "{{ claude_gcs_bucket }}/latest" |
| 54 | + return_content: true |
| 55 | + register: claude_latest_version |
| 56 | + |
| 57 | + - name: Set Claude Code version fact |
| 58 | + ansible.builtin.set_fact: |
| 59 | + claude_version: "{{ claude_latest_version.content | trim }}" |
| 60 | + |
| 61 | + - name: Determine Claude Code platform |
| 62 | + ansible.builtin.set_fact: |
| 63 | + claude_platform: >- |
| 64 | + {%- if ansible_facts['architecture'] == 'x86_64' -%} |
| 65 | + linux-x64 |
| 66 | + {%- elif ansible_facts['architecture'] == 'aarch64' -%} |
| 67 | + linux-arm64 |
| 68 | + {%- else -%} |
| 69 | + unsupported |
| 70 | + {%- endif -%} |
| 71 | +
|
| 72 | + - name: Fail if unsupported architecture |
| 73 | + ansible.builtin.fail: |
| 74 | + msg: "Unsupported architecture for Claude Code: {{ ansible_facts['architecture'] }}" |
| 75 | + when: claude_platform == 'unsupported' |
| 76 | + |
| 77 | + - name: Fetch Claude Code manifest for checksum |
| 78 | + ansible.builtin.uri: |
| 79 | + url: "{{ claude_gcs_bucket }}/{{ claude_version }}/manifest.json" |
| 80 | + return_content: true |
| 81 | + register: claude_manifest |
| 82 | + |
| 83 | + - name: Set Claude Code checksum fact |
| 84 | + ansible.builtin.set_fact: |
| 85 | + claude_checksum: "{{ claude_manifest.json.platforms[claude_platform].checksum }}" |
| 86 | + |
| 87 | + - name: Create temporary download directory |
| 88 | + ansible.builtin.file: |
| 89 | + path: /tmp/claude-install |
| 90 | + state: directory |
| 91 | + mode: '0755' |
| 92 | + |
| 93 | + - name: Download Claude Code binary with checksum verification |
| 94 | + ansible.builtin.get_url: |
| 95 | + url: "{{ claude_gcs_bucket }}/{{ claude_version }}/{{ claude_platform }}/claude" |
| 96 | + dest: /tmp/claude-install/claude |
| 97 | + mode: '0755' |
| 98 | + checksum: "sha256:{{ claude_checksum }}" |
| 99 | + |
| 100 | + - name: Create ~/.local/bin directory |
| 101 | + ansible.builtin.file: |
| 102 | + path: "{{ user_home }}/.local/bin" |
| 103 | + state: directory |
| 104 | + mode: '0755' |
| 105 | + owner: "{{ actual_user }}" |
| 106 | + group: "{{ actual_user }}" |
| 107 | + |
| 108 | + - name: Run claude install to set up launcher and shell integration |
| 109 | + ansible.builtin.command: |
| 110 | + cmd: /tmp/claude-install/claude install |
| 111 | + become: true |
| 112 | + become_user: "{{ actual_user }}" |
| 113 | + environment: |
| 114 | + HOME: "{{ user_home }}" |
| 115 | + register: claude_install_result |
| 116 | + changed_when: claude_install_result.rc == 0 |
| 117 | + |
| 118 | + - name: Remove temporary download directory |
| 119 | + ansible.builtin.file: |
| 120 | + path: /tmp/claude-install |
| 121 | + state: absent |
| 122 | + |
| 123 | + - name: Display Claude Code installation info |
| 124 | + ansible.builtin.debug: |
| 125 | + msg: "Claude Code {{ claude_version }} installed ({{ claude_platform }})" |
| 126 | + |
37 | 127 | when: ansible_facts['distribution'] in ['Fedora', 'Ubuntu'] |
38 | 128 |
|
39 | | -- name: Enable Claude Code auto-update (macOS) |
40 | | - ansible.builtin.command: |
41 | | - cmd: "{{ user_home }}/.npm-global/bin/claude config set auto_update true" |
42 | | - environment: |
43 | | - PATH: "/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:{{ user_home }}/.npm-global/bin:{{ ansible_facts['env'].PATH }}" |
| 129 | +# ============================================================================ |
| 130 | +# macOS - Homebrew cask installation |
| 131 | +# ============================================================================ |
| 132 | + |
| 133 | +- name: Install Claude Code via Homebrew cask (macOS) |
| 134 | + community.general.homebrew_cask: |
| 135 | + name: claude-code |
| 136 | + state: present |
44 | 137 | become: false |
45 | | - failed_when: false |
46 | | - changed_when: false |
| 138 | + environment: "{{ homebrew_cask_env }}" |
47 | 139 | when: ansible_facts['distribution'] == 'MacOSX' |
48 | 140 |
|
49 | 141 | # ============================================================================ |
|
0 commit comments