├── doc └── images │ └── ansible-syntax.png ├── Ansible.sublime-settings ├── Comments.tmPreferences ├── LICENSE.md ├── README.md └── Ansible.sublime-syntax /doc/images/ansible-syntax.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clifford-github/sublime-ansible/HEAD/doc/images/ansible-syntax.png -------------------------------------------------------------------------------- /Ansible.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | // YAML mandates that tabs aren't used for indentation 3 | "translate_tabs_to_spaces": true, 4 | 5 | // In practice, editing YAML files with anything other than two space 6 | // indentation is tedious, due to the "- " list prefix 7 | "tab_size": 2, 8 | } 9 | -------------------------------------------------------------------------------- /Comments.tmPreferences: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | scope 5 | source.ansible 6 | settings 7 | 8 | shellVariables 9 | 10 | 11 | name 12 | TM_COMMENT_START 13 | value 14 | # 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Clifford Sanders 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Syntax highlighting for Ansible files 2 | ===================================== 3 | 4 | ## Screenshot 5 | 6 | With color scheme Monokai 7 | 8 | ![Screenshot](https://raw.githubusercontent.com/clifford-github/sublime-ansible/master/doc/images/ansible-syntax.png) 9 | 10 | ## Installation 11 | 12 | I recommend install another package along with this one, "Apply Syntax" package since this syntax does not take ownership of yml nor yaml files. 13 | 14 | ### Package Manager 15 | 16 | First, install the Package Control plugin, instructions here: http://wbond.net/sublime_packages/package_control. 17 | 18 | Once you install Package Control, restart Sublime Text and bring up the Command Palette (`Command+Shift+P` on OS X, `Control+Shift+P` on Linux/Windows). 19 | 20 | Select "Package Control: Install Package", wait while Package Control fetches the latest package list, then select "Ansible" when the list appears. 21 | 22 | The advantage of using this method is that Package Control will automatically keep this package up to date with the latest version. 23 | 24 | ### Manual 25 | Clone the repository in your Sublime Text "Packages" directory: 26 | 27 | git clone https://github.com/clifford-github/sublime-ansible.git Ansible 28 | 29 | The "Packages" directory is located at: 30 | 31 | * OS X: 32 | `~/Library/Application Support/Sublime Text 2/Packages/` 33 | * Linux: 34 | `~/.Sublime Text 2/Packages/` 35 | * Windows: 36 | `%APPDATA%/Sublime Text 2/Packages/` 37 | -------------------------------------------------------------------------------- /Ansible.sublime-syntax: -------------------------------------------------------------------------------- 1 | %YAML 1.2 2 | --- 3 | name: Ansible 4 | scope: source.ansible 5 | version: 2 6 | 7 | variables: 8 | 9 | results: "(failed|succeeded|skipped)" 10 | operatos: |- 11 | (?x: 12 | \b(?: 13 | (is|or)(\snot)?|if|else|(un)?defined 14 | )\b 15 | ) 16 | builtin_functions: |- 17 | (?x: 18 | \b(?: 19 | d(efault)?|query|lookup 20 | |combine|selectattr|dict2items 21 | |product|list|query 22 | )\b 23 | ) 24 | 25 | builtin_tags: |- 26 | (?x: 27 | \b(?: 28 | block|recursive|macro 29 | |call|filter|set|extends|include|raw|debug|with 30 | |autoescape|trans|pluralize|scoped|as|do 31 | )\b 32 | ) 33 | 34 | contexts: 35 | 36 | main: 37 | - match: "" 38 | push: Packages/YAML/YAML.sublime-syntax 39 | with_prototype: 40 | # - include: comments 41 | - include: entity-ansible 42 | - include: constant-ansible 43 | - include: jinja 44 | # - include: when-control 45 | 46 | comments: 47 | - match: \# 48 | scope: punctuation.definition.comment.ansible 49 | push: comment_line 50 | 51 | comment_line: 52 | - meta_scope: comment.line.ansible 53 | - match: $\n? 54 | set: main 55 | 56 | entity-ansible: 57 | - match: '^\s*- name:.*$' 58 | scope: entity.name.ansible 59 | pop: true 60 | 61 | constant-results: 62 | - match: \b{{results}}\b 63 | scope: constant.other.ansible 64 | pop: true 65 | 66 | constant-ansible: 67 | - match: 'ansible_((?:\.)?\w+(\[\w\]+)?)+' 68 | scope: constant.other.ansible 69 | 70 | when-control: 71 | - match: '(?:(when)(:))' 72 | captures: 73 | 1: entity.name.tag.ansible 74 | 2: punctuation.separator.ansible 75 | - include: when-body 76 | 77 | when-body: 78 | - match: '^\s*-\s.*$' 79 | set: keyword-control 80 | 81 | keyword-control: 82 | - match: '\s{{operatos}}\s' 83 | scope: keyword.operator.word.ansible 84 | 85 | jinja: 86 | - match: \{{2} 87 | scope: punctuation.definition.placeholder.begin.ansible 88 | push: jinja-body 89 | 90 | jinja-body: 91 | - meta_scope: meta.placeholder.ansible 92 | - match: \}{2} 93 | scope: punctuation.definition.placeholder.end.ansible 94 | pop: true 95 | - include: jinja-expressions 96 | 97 | jinja-expressions: 98 | - include: match_keywords 99 | - include: constant-ansible 100 | - include: single-functions 101 | - include: functions 102 | 103 | match_keywords: 104 | - match: \b(for)\b 105 | scope: keyword.control.loop.for.ansible 106 | - match: \b(if)\b 107 | scope: keyword.control.conditional.if.ansible 108 | - match: \b(else)\b 109 | scope: keyword.control.conditional.else.ansible 110 | - match: \b(elif)\b 111 | scope: keyword.control.conditional.elseif.ansible 112 | - match: \b(continue)\b 113 | scope: keyword.control.flow.continue.ansible 114 | - match: \b(break)\b 115 | scope: keyword.control.flow.break.ansible 116 | - match: '{{builtin_tags}}' 117 | scope: keyword.other.tag.ansible 118 | - match: (\||==|!=) 119 | scope: keyword.other.tag.ansible 120 | 121 | single-functions: 122 | - match: (\s{{builtin_functions}}\s) 123 | scope: support.function.global.ansible 124 | 125 | functions: 126 | - match: (?:({{builtin_functions}})|(\w+))(\() 127 | captures: 128 | 1: support.function.global.ansible 129 | 2: variable.function.ansible 130 | 3: punctuation.section.arguments.begin.ansible 131 | push: 132 | - meta_content_scope: meta.function-call.arguments.ansible 133 | - match: \) 134 | scope: punctuation.section.arguments.end.ansible 135 | pop: true 136 | - match: '[a-zA-Z0-9_]+' 137 | scope: variable.parameter.ansible 138 | - match: \, 139 | scope: punctuation.separator.parameters.twig 140 | 141 | jinja-keyword-control: 142 | - match: (\||==|!=) 143 | scope: keyword.control.ansible 144 | pop: true 145 | 146 | jinja-end: 147 | - match: '}}' 148 | scope: punctuation.section.block.end.ansible 149 | pop: true 150 | set: 151 | - include: main 152 | 153 | string: 154 | - meta_scope: string.quoted.other.ansible 155 | - match: \'| \" 156 | scope: punctuation.definition.string.begin.ansible 157 | pop: true 158 | - match: \\. 159 | scope: constant.character.escape.ansible 160 | --------------------------------------------------------------------------------