From 7c2ff0e66b030a758daf53dfff1f26db30e62052 Mon Sep 17 00:00:00 2001 From: THEBAULT Julien Date: Fri, 23 Oct 2015 20:17:33 +0200 Subject: [PATCH 1/2] Ansible-galaxy support the include directive --- lib/ansible/cli/galaxy.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 17f06409bb..c44df5a343 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -368,11 +368,23 @@ class GalaxyCLI(CLI): raise AnsibleError("No roles found in file: %s" % role_file) for role in required_roles: - role = RoleRequirement.role_yaml_parse(role) - display.vvv('found role %s in yaml file' % str(role)) - if 'name' not in role and 'scm' not in role: - raise AnsibleError("Must specify name or src for role") - roles_left.append(GalaxyRole(self.galaxy, **role)) + if "include" not in role: + role = RoleRequirement.role_yaml_parse(role) + display.vvv("found role %s in yaml file" % str(role)) + if "name" not in role and "scm" not in role: + raise AnsibleError("Must specify name or src for role") + roles_left.append(GalaxyRole(self.galaxy, **role)) + else: + with open(role["include"]) as f_include: + try: + roles_left += [ + GalaxyRole(self.galaxy, **r) for r in + map(RoleRequirement.role_yaml_parse, + yaml.safe_load(f_include)) + ] + except Exception as e: + msg = "Unable to load data from the include requirements file: %s %s" + raise AnsibleError(msg % (role_file, e)) else: display.deprecated("going forward only the yaml format will be supported") # roles listed in a file, one per line From fd67d911c334a2c1b11949347dd0876775cff70a Mon Sep 17 00:00:00 2001 From: THEBAULT Julien Date: Fri, 23 Oct 2015 20:31:00 +0200 Subject: [PATCH 2/2] Update doc for the ansible-galaxy include directive --- docsite/rst/galaxy.rst | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/docsite/rst/galaxy.rst b/docsite/rst/galaxy.rst index ba841eed09..65d3b4f784 100644 --- a/docsite/rst/galaxy.rst +++ b/docsite/rst/galaxy.rst @@ -68,6 +68,28 @@ To request specific versions (tags) of a role, use this syntax in the roles file Available versions will be listed on the Ansible Galaxy webpage for that role. +Installing Multiple Roles From Multiple Files +============================================= + +At a basic level, including requirements files allows you to break up bits of configuration policy into smaller files. Role includes pull in roles from other files. + + ansible-galaxy install -r requirements.yml + + # from galaxy + - src: yatesr.timezone + + - include: webserver.yml + + +Content of the webserver.yml file. + + # from github + - src: https://github.com/bennojoy/nginx + + # from github installing to a relative path + - src: https://github.com/bennojoy/nginx + path: vagrant/roles/ + Advanced Control over Role Requirements Files ============================================= @@ -385,19 +407,3 @@ Use the --remove option to disable and remove a Travis integration: Provide the ID of the integration you want disabled. Use the --list option to get the ID. - - - - - - - - - - - - - - - -