diff --git a/.overcommit.yml b/.overcommit.yml new file mode 100644 index 0000000..3037a42 --- /dev/null +++ b/.overcommit.yml @@ -0,0 +1,33 @@ +# Use this file to configure the Overcommit hooks you wish to use. This will +# extend the default configuration defined in: +# https://github.com/brigade/overcommit/blob/master/config/default.yml +# +# At the topmost level of this YAML file is a key representing type of hook +# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can +# customize each hook, such as whether to only run it on certain files (via +# `include`), whether to only display output if it fails (via `quiet`), etc. +# +# For a complete list of hooks, see: +# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook +# +# For a complete list of options that you can use to customize hooks, see: +# https://github.com/brigade/overcommit#configuration +# +# Uncomment the following lines to make the configuration take effect. + +#PreCommit: +# RuboCop: +# enabled: true +# on_warn: fail # Treat all warnings as failures +# +# TrailingWhitespace: +# enabled: true +# exclude: +# - '**/db/structure.sql' # Ignore trailing whitespace in generated files +# +#PostCheckout: +# ALL: # Special hook name that customizes all hooks of this type +# quiet: true # Change all post-checkout hooks to only display output on failure +# +# IndexTags: +# enabled: true # Generate a tags file with `ctags` each time HEAD changes diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5e3a1f0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +--- +sudo: required +language: python +services: + - docker +before_install: + - sudo apt-get -qq update +install: + - pip install molecule docker-py +script: + - molecule test diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..ad0be76 --- /dev/null +++ b/.yamllint @@ -0,0 +1,11 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable diff --git a/README.md b/README.md new file mode 100644 index 0000000..dbae63d --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: azmodude.visual-studio-code, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..581a7db --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for azmodude.visual-studio-code diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..91d02fc --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for azmodude.visual-studio-code diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..ba43fdd --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,58 @@ +--- +galaxy_info: + author: your name + description: your description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + + min_ansible_version: 1.2 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # Optionally specify the branch Galaxy will use when accessing the GitHub + # repo for this role. During role install, if no tags are available, + # Galaxy will use this branch. During import Galaxy will access files on + # this branch. If Travis integration is configured, only notifications for this + # branch will be accepted. Otherwise, in all cases, the repo's default branch + # (usually master) will be used. + # github_branch: + + # + # platforms is a list of platforms, and each platform has a name and a list of versions. + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] +# List your role dependencies here, one per line. Be sure to remove the '[]' above, +# if you add dependencies to this list. diff --git a/molecule/default/.cache/v/cache/lastfailed b/molecule/default/.cache/v/cache/lastfailed new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/molecule/default/.cache/v/cache/lastfailed @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/molecule/default/.molecule/Dockerfile_centos b/molecule/default/.molecule/Dockerfile_centos new file mode 100644 index 0000000..a82ca1a --- /dev/null +++ b/molecule/default/.molecule/Dockerfile_centos @@ -0,0 +1,9 @@ +# Molecule managed + +FROM centos + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; fi diff --git a/molecule/default/.molecule/Dockerfile_fedora b/molecule/default/.molecule/Dockerfile_fedora new file mode 100644 index 0000000..c676d04 --- /dev/null +++ b/molecule/default/.molecule/Dockerfile_fedora @@ -0,0 +1,9 @@ +# Molecule managed + +FROM fedora + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; fi diff --git a/molecule/default/.molecule/Dockerfile_ubuntu b/molecule/default/.molecule/Dockerfile_ubuntu new file mode 100644 index 0000000..010c103 --- /dev/null +++ b/molecule/default/.molecule/Dockerfile_ubuntu @@ -0,0 +1,9 @@ +# Molecule managed + +FROM ubuntu + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; fi diff --git a/molecule/default/.molecule/ansible.cfg b/molecule/default/.molecule/ansible.cfg new file mode 100644 index 0000000..761e8ce --- /dev/null +++ b/molecule/default/.molecule/ansible.cfg @@ -0,0 +1,10 @@ +# Molecule managed + +[ssh_connection] +control_path = %(directory)s/%%h-%%p-%%r +scp_if_ssh = True +[defaults] +host_key_checking = False +ansible_managed = Ansible managed: Do NOT edit this file manually! +retry_files_enabled = False +nocows = 1 diff --git a/molecule/default/.molecule/ansible_inventory.yml b/molecule/default/.molecule/ansible_inventory.yml new file mode 100644 index 0000000..f3a3bb9 --- /dev/null +++ b/molecule/default/.molecule/ansible_inventory.yml @@ -0,0 +1,26 @@ +# Molecule managed + +--- +all: + hosts: + centos_7: &id001 + ansible_connection: docker + fedora_25: &id002 + ansible_connection: docker + fedora_26: &id003 + ansible_connection: docker + ubuntu_artful: &id004 + ansible_connection: docker + ubuntu_xenial: &id005 + ansible_connection: docker + ubuntu_zesty: &id006 + ansible_connection: docker +ungrouped: + hosts: + centos_7: *id001 + fedora_25: *id002 + fedora_26: *id003 + ubuntu_artful: *id004 + ubuntu_xenial: *id005 + ubuntu_zesty: *id006 + vars: {} diff --git a/molecule/default/.molecule/state.yml b/molecule/default/.molecule/state.yml new file mode 100644 index 0000000..95ee5e8 --- /dev/null +++ b/molecule/default/.molecule/state.yml @@ -0,0 +1,7 @@ +# Molecule managed + +--- +converged: true +created: true +driver: docker +prepared: true diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..f8b4e75 --- /dev/null +++ b/molecule/default/Dockerfile.j2 @@ -0,0 +1,9 @@ +# Molecule managed + +FROM {{ item.image }} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum update -y && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper update -y && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; fi diff --git a/molecule/default/INSTALL.rst b/molecule/default/INSTALL.rst new file mode 100644 index 0000000..e26493b --- /dev/null +++ b/molecule/default/INSTALL.rst @@ -0,0 +1,16 @@ +******* +Install +******* + +Requirements +============ + +* Docker Engine +* docker-py + +Install +======= + +.. code-block:: bash + + $ sudo pip install docker-py diff --git a/molecule/default/create.yml b/molecule/default/create.yml new file mode 100644 index 0000000..11d5c69 --- /dev/null +++ b/molecule/default/create.yml @@ -0,0 +1,47 @@ +--- +- name: Create + hosts: localhost + connection: local + gather_facts: False + no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" + vars: + molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}" + molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}" + molecule_scenario_directory: "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}" + molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}" + tasks: + - name: Create Dockerfiles from image names + template: + src: "{{ molecule_scenario_directory }}/Dockerfile.j2" + dest: "{{ molecule_ephemeral_directory }}/Dockerfile_{{ item.image | regex_replace('[^a-zA-Z0-9_]', '_') }}" + with_items: "{{ molecule_yml.platforms }}" + register: platforms + + - name: Discover local Docker images + docker_image_facts: + name: "molecule_local/{{ item.item.name }}" + with_items: "{{ platforms.results }}" + register: docker_images + + - name: Build an Ansible compatible image + docker_image: + path: "{{ molecule_ephemeral_directory }}" + name: "molecule_local/{{ item.item.image }}" + dockerfile: "{{ item.item.dockerfile | default(item.invocation.module_args.dest) }}" + force: "{{ item.item.force | default(True) }}" + with_items: "{{ platforms.results }}" + when: platforms.changed or docker_images.results | map(attribute='images') | select('equalto', []) | list | count >= 0 + + - name: Create molecule instance(s) + docker_container: + name: "{{ item.name }}" + hostname: "{{ item.name }}" + image: "molecule_local/{{ item.image }}" + state: started + recreate: False + log_driver: syslog + command: "{{ item.command | default('sleep infinity') }}" + privileged: "{{ item.privileged | default(omit) }}" + volumes: "{{ item.volumes | default(omit) }}" + capabilities: "{{ item.capabilities | default(omit) }}" + with_items: "{{ molecule_yml.platforms }}" diff --git a/molecule/default/destroy.yml b/molecule/default/destroy.yml new file mode 100644 index 0000000..f31ee27 --- /dev/null +++ b/molecule/default/destroy.yml @@ -0,0 +1,16 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: False + no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" + vars: + molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}" + molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}" + tasks: + - name: Destroy molecule instance(s) + docker_container: + name: "{{ item.name }}" + state: absent + force_kill: "{{ item.force_kill | default(True) }}" + with_items: "{{ molecule_yml.platforms }}" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..38ad32e --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,37 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: ubuntu_xenial + image: ubuntu + image_version: 16.04 + - name: ubuntu_zesty + image: ubuntu + image_version: 17.04 + - name: ubuntu_artful + image: ubuntu + image_version: 17.10 + - name: centos_7 + image: centos + image_version: 7 + - name: fedora_25 + image: fedora + image_version: 25 + - name: fedora_26 + image: fedora + image_version: 26 + +provisioner: + name: ansible + lint: + name: ansible-lint +scenario: + name: default +verifier: + name: testinfra + lint: + name: flake8 diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml new file mode 100644 index 0000000..74d1c47 --- /dev/null +++ b/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: azmodude.visual-studio-code diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml new file mode 100644 index 0000000..d34f067 --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare + hosts: all + gather_facts: False + tasks: [] diff --git a/molecule/default/tests/__pycache__/test_default.cpython-27-PYTEST.pyc b/molecule/default/tests/__pycache__/test_default.cpython-27-PYTEST.pyc new file mode 100644 index 0000000..2c94edb Binary files /dev/null and b/molecule/default/tests/__pycache__/test_default.cpython-27-PYTEST.pyc differ diff --git a/molecule/default/tests/__pycache__/test_vscode.cpython-27-PYTEST.pyc b/molecule/default/tests/__pycache__/test_vscode.cpython-27-PYTEST.pyc new file mode 100644 index 0000000..ba8a2b0 Binary files /dev/null and b/molecule/default/tests/__pycache__/test_vscode.cpython-27-PYTEST.pyc differ diff --git a/molecule/default/tests/test_default.pyc b/molecule/default/tests/test_default.pyc new file mode 100644 index 0000000..2dd2448 Binary files /dev/null and b/molecule/default/tests/test_default.pyc differ diff --git a/molecule/default/tests/test_vscode.py b/molecule/default/tests/test_vscode.py new file mode 100644 index 0000000..2299f38 --- /dev/null +++ b/molecule/default/tests/test_vscode.py @@ -0,0 +1,20 @@ +import os +import testinfra.utils.ansible_runner + + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_vscode_package(host): + assert host.package("code").is_installed + + +def test_vscode_installed(host): + assert host.file("/usr/bin/code").exists and \ + host.file("/usr/bin/code").is_file + + +def test_vscode_mayrun(host): + command = "/usr/bin/code --user-data-dir=/tmp --help" + assert "Visual Studio Code" in host.command(command).stdout.split("\n")[0] diff --git a/tasks/debian.yml b/tasks/debian.yml new file mode 100644 index 0000000..41b584f --- /dev/null +++ b/tasks/debian.yml @@ -0,0 +1,27 @@ +--- +- name: Install apt-transport-https + apt: + name: apt-transport-https + state: present + +- name: Install Microsoft GPG key + apt_key: + url: "https://packages.microsoft.com/keys/microsoft.asc" + state: present + +- name: Add Microsoft Visual Studio Code Repository + apt_repository: + repo: 'deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main' + filename: vscode + state: present + update_cache: yes + +- name: Install Visual Studio Code including dependencies + apt: + name: "{{ item }}" + update_cache: true + with_items: + - libgtk2.0-0 + - libxss1 + - libasound2 + - code diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..4e33a6d --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- include_tasks: "debian.yml" + when: ansible_os_family == "Debian" +- include_tasks: "redhat.yml" + when: ansible_os_family == "RedHat" diff --git a/tasks/redhat.yml b/tasks/redhat.yml new file mode 100644 index 0000000..8fa02a2 --- /dev/null +++ b/tasks/redhat.yml @@ -0,0 +1,16 @@ +--- +- name: Add Microsoft Visual Studio Code repository + yum_repository: + name: vscode + description: vscode + file: vscode + gpgkey: https://packages.microsoft.com/keys/microsoft.asc + baseurl: https://packages.microsoft.com/yumrepos/vscode + +- name: Install Visual Studio Code including dependencies + package: + name: "{{ item }}" + state: present + with_items: + - which + - code diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..2abf883 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for azmodude.visual-studio-code