我正在尝试使用Ansible安装Sublime Text(在Ubuntu上)。这是我试图用来完成这个的基本Ansible剧本,基于:
Ansible docs apt-repository和apt-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 docs here,但我不知道如何将其转换为SublimeText案例。
问题:
在SublimeText指令中,步骤1:指定了指向GPG密钥的直接链接。他们说:
Install the GPG key: https://download.sublimetext.com/sublimehq-pub.gpg
但如何使用Ansible apt_key
模块添加此内容?
apt_repository
的任务是否对应于bash命令echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
答案 0 :(得分: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 }}"
答案 1 :(得分:2)
对于Fedora 32,以下内容是我main.yaml的一部分。当然,请删除...,然后根据需要进行编辑:-)
- hosts: fedora
become: true
tasks:
...
- name: Add Sublime repository
yum_repository:
name: sublime-text
description: Sublime Text x86_64 - stable
baseurl: https://download.sublimetext.com/rpm/stable/x86_64
enabled: yes
gpgcheck: yes
- name: Add Sublime Text
dnf:
name: sublime-text
state: present
...