2017-10-19 108 views
0

我想在Ansible上安裝Sublime Text(在Ubuntu上)。下面是基本Ansible劇本,我嘗試使用爲實現這一點,基於:Ansible在Linux中安裝Sublime文本編輯器

  1. 的bash命令here安裝崇高文本
  2. Ansible文檔apt-repositoryapt-key

    --- 
    - 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文檔here,但我不知道如何將其轉換爲SublimeText格式。

問題:

  1. 在SublimeText指令,步驟1:一個直接鏈接到GPG密鑰被指定。他們說:

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

    但我怎麼添加這個使用Ansible apt_key模塊?

  2. 在步驟2:是否使用任務apt_repository對應bash命令echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list

回答

1
--- 
- 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 }}" 
+0

爲什麼你在這裏有引號:'with_items: - 「{{my_pkgs}}」'?由於'{{my_pkgs}}'不遵循':',所以''with_items: - {{my_pkgs}}'可以接受嗎? –

+0

另外,是否'with_items: - {{my_pkgs}}'可單獨接受爲'with_items: - my_pkgs',並且'{{}}'? –

+1

1.始終引用模板表達式括號,當它們 開始一個值時。 – Nickolay

相關問題