Setting up SublimeText 3 for Ansible

I love using Sublime Text 3 for Ansible work, especially after some minor tweaks. The packages I have installed are: Ansible syntax highlighting, ApplySyntax, Jinja2 syntax support, SublimeLinter, and SublimeLinter-pyyaml.

For ApplySyntax you want to change the user settings to contain something like the following below. It's based on the best practices for Ansible directory layout, but with one change, I prefer to have playbooks in their own subdirectory.

{
    "syntaxes": [
        {
            "syntax": "Ansible/Ansible",
            "rules": [
                { "file_path": ".*/defaults/.*.ya?ml$" },
                { "file_path": ".*/handlers/.*.ya?ml$" },
                { "file_path": ".*/meta/.*.ya?ml$" },
                { "file_path": ".*/tasks/.*.ya?ml$" },
                { "file_path": ".*/vars/.*.ya?ml$" },
                { "file_path": ".*/inventory/group_vars/.*" },
                { "file_path": ".*/inventory/host_vars/.*" },
                { "file_path": ".*/inventory/.*" },
                { "file_path": ".*/playbooks/.*.ya?ml$" }
            ]
        },
        {
            "syntax": "Jinja2/Syntaxes/Jinja Templates",
            "rules": [
                { "file_path": ".*/templates/.*.j2$" }
            ]
        }
    ]
}

The above will ensure that the Ansible syntax highlighting gets used for the regular expressions defined in the file_path matches.

Then in the SublimeLinter user settings make sure that syntax_map contains an entry "ansible": "yaml". This will ensure that all views marked with the Ansible file type will now automatically use the SublimeLinter-pyyaml linter.

Ansible, URLs, proxies and connection refused

So today I was trying to fix a problem with the deployment of some software with Ansible. I am using get_url in combination with a http_proxy environment setting in order to pull a file in from a HTTP URL. However, when I ran the playbook I was greeted with a [Errno 111] Connection refused error message. After fixing the proxy to have the netblock properly configured I tested again and was again greeted by the error. The problem became more confounding when I ran a test with curl on the command line using the proxy parameters, this test actually worked. So the proxy was running as it should. After some long testing and trying to figure out just what was going wrong, I replaced the get_url with a command: curl set up to test if it might be Ansible itself. The output of curl was enlightening, it turned out the HTTP URL was 301 redirecting to another HTTP URL, which in turn was 302 redirecting to a HTTPS URL! And since I wanted to be explicit I had not added the https_proxy environment variable.

The problem however now comes in how to to fix this. Is it documentation? Ansible code fix? Python code fix?