首页 文章

Ansible在Linux中安装Sublime Text编辑器

提问于
浏览
1

我正在尝试使用Ansible安装Sublime Text(在Ubuntu上) . 这是我试图用来完成这个的基本Ansible剧本,基于:

---
- hosts: all
vars:
  - my_repos:
      - ppa: https://download.sublimetext.com/
      - ppa: [arch=amd64] http://dl.google.com/linux/chrome/deb/
  - my_pkgs:
      - sublime-text
      - google-chrome-stable

tasks:
  - Install GPG key
    name: install GPG key for SubLimeText
    ???????

  - name: Add specified repositories into sources list using specified filename
    apt_repository: repo=deb {{ item }} stable main
                    state=present
                    filename='{{ item }}'
    with_items:
      - my_repos

  - name: Install packages
    apt: state=installed pkg={{ item }}
    with_items:
      - my_pkgs

第一个任务是为SublimeText安装GPG密钥(按照上面的第一个链接) . 我阅读了Ansible docs here,但我不知道如何将其转换为SublimeText案例 .

Questions:

  • 在SublimeText指令中,步骤1:指定了指向GPG密钥的直接链接 . 他们说:

Install the GPG key: https://download.sublimetext.com/sublimehq-pub.gpg

但是如何使用Ansible apt_key 模块添加它?

  • 在步骤2中:使用 apt_repository 的任务是否对应于bash命令 echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

1 回答

  • 3
    ---
    - hosts: all
      vars:
        - my_pkgs:
          - sublime-text
          - google-chrome-stable
    
      tasks:
      - name: Install GPG key for SubLimeText
        apt_key:
          url: https://download.sublimetext.com/sublimehq-pub.gpg
          state: present
    
      - name: Add specified repositories into sources list using specified filename
        apt_repository:
          repo: deb {{ item.repo }} {{ item.add }}
          state: present
          filename: "{{ item.file }}"
        with_items:
          - repo: https://download.sublimetext.com/
            add: apt/stable/
            file: sublime
          - repo: '[arch=amd64] http://dl.google.com/linux/chrome/deb/'
            add: stable main
            file: google-chrome
    
      - name: Install packages
        apt:
          state: installed
          pkg: "{{ item }}"
          update_cache: yes
        with_items:
          - "{{ my_pkgs }}"
    

相关问题