--- - name: Install multiple packages on localhost for arm64 and amd64 architectures hosts: localhost gather_facts: true connection: local become: true become_method: sudo tasks: - name: Update package list apt: update_cache: yes - name: Install general packages apt: name: "{{ item }}" state: present loop: - vim - htop - nginx when: ansible_architecture in ["aarch64", "amd64"] - name: Add PHP repository apt_repository: repo: ppa:ondrej/php when: ansible_architecture in ["aarch64", "amd64"] - name: Try to install PHP 8.2 block: - name: Install PHP 8.2 packages apt: name: "{{ item }}" state: present loop: - php8.2 - php8.2-cli - php8.2-fpm - php8.2-json - php8.2-common - php8.2-mysql - php8.2-zip - php8.2-gd - php8.2-mbstring - php8.2-curl - php8.2-xml - php8.2-bcmath rescue: - name: Handle failure debug: msg: "An error occurred during PHP 8.2 package installation. Proceeding to next task." when: ansible_architecture in ["aarch64", "amd64"] - name: Install MySQL 8.0 apt: name: mysql-server state: present when: ansible_architecture in ["aarch64", "amd64"] - name: Install PHPMyAdmin apt: name: phpmyadmin state: present when: ansible_architecture in ["aarch64", "amd64"] - name: Download NVM install script get_url: url: "https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh" dest: "/tmp/nvm_install.sh" mode: "0755" when: ansible_architecture in ["aarch64", "amd64"] - name: Install NVM (Node Version Manager) command: cmd: "/bin/bash /tmp/nvm_install.sh" creates: "$HOME/.nvm/nvm.sh" when: ansible_architecture in ["aarch64", "amd64"]