Markus Falb 2 weeks ago committed by GitHub
commit e7ab42f86b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,7 @@
---
minor_changes:
- >-
If a collection-skeleton is used with ansible-galaxy collection init
or role init and both a file and file.j2 are present, only copy file.j2
(https://github.com/ansible/ansible/pull/82624)
...

@ -1224,6 +1224,9 @@ class GalaxyCLI(CLI):
raise AnsibleError(f"Failed to create {galaxy_type.title()} {obj_name}. Templating {src_template} failed with the error: {e}") from e
with open(dest_file, 'wb') as df:
df.write(b_rendered)
elif f + '.j2' in files and not in_templates_dir:
# We have two possible sources for the same file, we prefer the jinja template
continue
else:
f_rel_path = os.path.relpath(os.path.join(root, f), obj_skeleton)
shutil.copyfile(os.path.join(root, f), os.path.join(obj_path, f_rel_path), follow_symlinks=False)

@ -189,7 +189,6 @@ lib/ansible/galaxy/data/network/README.md pymarkdown:line-length
README.md pymarkdown:line-length
test/integration/targets/ansible-vault/invalid_format/README.md pymarkdown:no-bare-urls
test/support/README.md pymarkdown:no-bare-urls
test/units/cli/test_data/role_skeleton/README.md pymarkdown:line-length
test/integration/targets/find/files/hello_world.gbk no-smart-quotes
test/integration/targets/find/files/hello_world.gbk no-unwanted-characters
lib/ansible/galaxy/collection/__init__.py pylint:ansible-deprecated-version-comment # 2.18 deprecation

@ -1 +1 @@
A readme
A readme which is masked by README.md.j2

@ -1,38 +1,5 @@
Role Name
=========
README for Role skeleton
========================
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: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
This is not the file that goes into a newly created role.
The role gets README.md.j2

@ -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: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

@ -0,0 +1,2 @@
[defaults]
test_key = not_a_jinja_file_at_all

@ -319,7 +319,11 @@ class ValidRoleTests(object):
with open(os.path.join(self.role_dir, 'README.md'), 'r') as readme:
contents = readme.read()
with open(os.path.join(self.role_skeleton_path, 'README.md'), 'r') as f:
if os.path.exists(os.path.join(self.role_skeleton_path, 'README.md.j2')):
readme_filename = 'README.md.j2'
else:
readme_filename = 'README.md'
with open(os.path.join(self.role_skeleton_path, readme_filename), 'r') as f:
expected_contents = f.read()
self.assertEqual(expected_contents, contents, msg='README.md does not match expected')
@ -442,6 +446,14 @@ class TestGalaxyInitSkeleton(unittest.TestCase, ValidRoleTests):
expected_contents = '[defaults]\ntest_key = {{ test_variable }}'
self.assertEqual(expected_contents, contents.strip(), msg="test.conf.j2 doesn't contain what it should, is it being rendered?")
def test_file_not_masked_by_template(self):
test_conf = os.path.join(self.role_dir, 'templates', 'test.conf')
self.assertTrue(os.path.exists(test_conf), msg="The test.conf file doesn't seem to exist, was it not copied because test.conf.j2 does exist too?")
with open(test_conf, 'r') as f:
contents = f.read()
expected_contents = '[defaults]\ntest_key = not_a_jinja_file_at_all'
self.assertEqual(expected_contents, contents.strip(), msg="test.conf doesn't contain what it should, is it being rendered?")
def test_template_ignore_jinja_subfolder(self):
test_conf_j2 = os.path.join(self.role_dir, 'templates', 'subfolder', 'test.conf.j2')
self.assertTrue(os.path.exists(test_conf_j2), msg="The test.conf.j2 template doesn't seem to exist, is it being rendered as test.conf?")

@ -439,6 +439,15 @@ def test_timeout_server_config(timeout_cli, timeout_cfg, timeout_fallback, expec
assert galaxy_cli.api_servers[0].timeout == expected_timeout
def test_init_collection(collection_input):
input_dir, output_dir = collection_input
file_hash = secure_hash_s(open(os.path.join(input_dir, 'README.md')).read())
assert file_hash == '08f24200b9fbe18903e7a50930c9d0df0b8d7da3' # shasum test/units/cli/test_data/collection_skeleton/README.md.j2
assert os.path.isfile(os.path.join(input_dir, 'roles/common/templates/file-a.j2'))
assert os.path.isfile(os.path.join(input_dir, 'roles/common/templates/file-a'))
def test_build_collection_no_galaxy_yaml():
fake_path = u'/fake/ÅÑŚÌβŁÈ/path'
expected = to_native("The collection galaxy.yml path '%s/galaxy.yml' does not exist." % fake_path)
@ -838,7 +847,7 @@ def test_build_with_symlink_inside_collection(collection_input):
actual_file = secure_hash_s(linked_file_obj.read())
linked_file_obj.close()
assert actual_file == '08f24200b9fbe18903e7a50930c9d0df0b8d7da3' # shasum test/units/cli/test_data/collection_skeleton/README.md
assert actual_file == '08f24200b9fbe18903e7a50930c9d0df0b8d7da3' # shasum test/units/cli/test_data/collection_skeleton/README.md.j2
def test_publish_no_wait(galaxy_server, collection_artifact, monkeypatch):

Loading…
Cancel
Save