status
stringclasses 1
value | repo_name
stringclasses 31
values | repo_url
stringclasses 31
values | issue_id
int64 1
104k
| title
stringlengths 4
233
| body
stringlengths 0
186k
⌀ | issue_url
stringlengths 38
56
| pull_url
stringlengths 37
54
| before_fix_sha
stringlengths 40
40
| after_fix_sha
stringlengths 40
40
| report_datetime
timestamp[us, tz=UTC] | language
stringclasses 5
values | commit_datetime
timestamp[us, tz=UTC] | updated_file
stringlengths 7
188
| chunk_content
stringlengths 1
1.03M
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
verify_parser.add_argument('--ignore-signature-status-codes', dest='ignore_gpg_errors', type=str, action='extend', nargs='+',
help=ignore_gpg_status_help, default=C.GALAXY_IGNORE_INVALID_SIGNATURE_STATUS_CODES,
choices=list(GPG_ERROR_MAP.keys()))
def add_install_options(self, parser, parents=None):
galaxy_type = 'collection' if parser.metavar == 'COLLECTION_ACTION' else 'role'
args_kwargs = {}
if galaxy_type == 'collection':
args_kwargs['help'] = 'The collection(s) name or path/url to a tar.gz collection artifact. This is ' \
'mutually exclusive with --requirements-file.'
ignore_errors_help = 'Ignore errors during installation and continue with the next specified ' \
'collection. This will not ignore dependency conflict errors.'
else:
args_kwargs['help'] = 'Role name, URL or tar file'
ignore_errors_help = 'Ignore errors and continue with the next specified role.'
install_parser = parser.add_parser('install', parents=parents,
help='Install {0}(s) from file(s), URL(s) or Ansible '
'Galaxy'.format(galaxy_type))
install_parser.set_defaults(func=self.execute_install)
install_parser.add_argument('args', metavar='{0}_name'.format(galaxy_type), nargs='*', **args_kwargs)
install_parser.add_argument('-i', '--ignore-errors', dest='ignore_errors', action='store_true', default=False,
help=ignore_errors_help)
install_exclusive = install_parser.add_mutually_exclusive_group()
install_exclusive.add_argument('-n', '--no-deps', dest='no_deps', action='store_true', default=False,
help="Don't download {0}s listed as dependencies.".format(galaxy_type))
install_exclusive.add_argument('--force-with-deps', dest='force_with_deps', action='store_true', default=False,
help="Force overwriting an existing {0} and its "
"dependencies.".format(galaxy_type))
valid_signature_count_help = 'The number of signatures that must successfully verify the collection. This should be a positive integer ' \
'or -1 to signify that all signatures must be used to verify the collection. ' \
'Prepend the value with + to fail if no valid signatures are found for the collection (e.g. +all).'
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
ignore_gpg_status_help = 'A space separated list of status codes to ignore during signature verification (for example, NO_PUBKEY FAILURE). ' \
'Descriptions for the choices can be seen at L(https://github.com/gpg/gnupg/blob/master/doc/DETAILS#general-status-codes).' \
'Note: specify these after positional arguments or use -- to separate them.'
if galaxy_type == 'collection':
install_parser.add_argument('-p', '--collections-path', dest='collections_path',
default=self._get_default_collection_path(),
help='The path to the directory containing your collections.')
install_parser.add_argument('-r', '--requirements-file', dest='requirements',
help='A file containing a list of collections to be installed.')
install_parser.add_argument('--pre', dest='allow_pre_release', action='store_true',
help='Include pre-release versions. Semantic versioning pre-releases are ignored by default')
install_parser.add_argument('-U', '--upgrade', dest='upgrade', action='store_true', default=False,
help='Upgrade installed collection artifacts. This will also update dependencies unless --no-deps is provided')
install_parser.add_argument('--keyring', dest='keyring', default=C.GALAXY_GPG_KEYRING,
help='The keyring used during signature verification')
install_parser.add_argument('--disable-gpg-verify', dest='disable_gpg_verify', action='store_true',
default=C.GALAXY_DISABLE_GPG_VERIFY,
help='Disable GPG signature verification when installing collections from a Galaxy server')
install_parser.add_argument('--signature', dest='signatures', action='append',
help='An additional signature source to verify the authenticity of the MANIFEST.json before '
'installing the collection from a Galaxy server. Use in conjunction with a positional '
'collection name (mutually exclusive with --requirements-file).')
install_parser.add_argument('--required-valid-signature-count', dest='required_valid_signature_count', type=validate_signature_count,
help=valid_signature_count_help, default=C.GALAXY_REQUIRED_VALID_SIGNATURE_COUNT)
install_parser.add_argument('--ignore-signature-status-code', dest='ignore_gpg_errors', type=str, action='append',
help=opt_help.argparse.SUPPRESS, default=C.GALAXY_IGNORE_INVALID_SIGNATURE_STATUS_CODES,
choices=list(GPG_ERROR_MAP.keys()))
install_parser.add_argument('--ignore-signature-status-codes', dest='ignore_gpg_errors', type=str, action='extend', nargs='+',
help=ignore_gpg_status_help, default=C.GALAXY_IGNORE_INVALID_SIGNATURE_STATUS_CODES,
choices=list(GPG_ERROR_MAP.keys()))
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
install_parser.add_argument('--offline', dest='offline', action='store_true', default=False,
help='Install collection artifacts (tarballs) without contacting any distribution servers. '
'This does not apply to collections in remote Git repositories or URLs to remote tarballs.'
)
else:
install_parser.add_argument('-r', '--role-file', dest='requirements',
help='A file containing a list of roles to be installed.')
r_re = re.compile(r'^(?<!-)-[a-zA-Z]*r[a-zA-Z]*')
contains_r = bool([a for a in self._raw_args if r_re.match(a)])
role_file_re = re.compile(r'--role-file($|=)')
contains_role_file = bool([a for a in self._raw_args if role_file_re.match(a)])
if self._implicit_role and (contains_r or contains_role_file):
install_parser.add_argument('--keyring', dest='keyring', default=C.GALAXY_GPG_KEYRING,
help='The keyring used during collection signature verification')
install_parser.add_argument('--disable-gpg-verify', dest='disable_gpg_verify', action='store_true',
default=C.GALAXY_DISABLE_GPG_VERIFY,
help='Disable GPG signature verification when installing collections from a Galaxy server')
install_parser.add_argument('--required-valid-signature-count', dest='required_valid_signature_count', type=validate_signature_count,
help=valid_signature_count_help, default=C.GALAXY_REQUIRED_VALID_SIGNATURE_COUNT)
install_parser.add_argument('--ignore-signature-status-code', dest='ignore_gpg_errors', type=str, action='append',
help=opt_help.argparse.SUPPRESS, default=C.GALAXY_IGNORE_INVALID_SIGNATURE_STATUS_CODES,
choices=list(GPG_ERROR_MAP.keys()))
install_parser.add_argument('--ignore-signature-status-codes', dest='ignore_gpg_errors', type=str, action='extend', nargs='+',
help=ignore_gpg_status_help, default=C.GALAXY_IGNORE_INVALID_SIGNATURE_STATUS_CODES,
choices=list(GPG_ERROR_MAP.keys()))
install_parser.add_argument('-g', '--keep-scm-meta', dest='keep_scm_meta', action='store_true',
default=False,
help='Use tar instead of the scm archive option when packaging the role.')
def add_build_options(self, parser, parents=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
build_parser = parser.add_parser('build', parents=parents,
help='Build an Ansible collection artifact that can be published to Ansible '
'Galaxy.')
build_parser.set_defaults(func=self.execute_build)
build_parser.add_argument('args', metavar='collection', nargs='*', default=('.',),
help='Path to the collection(s) directory to build. This should be the directory '
'that contains the galaxy.yml file. The default is the current working '
'directory.')
build_parser.add_argument('--output-path', dest='output_path', default='./',
help='The path in which the collection is built to. The default is the current '
'working directory.')
def add_publish_options(self, parser, parents=None):
publish_parser = parser.add_parser('publish', parents=parents,
help='Publish a collection artifact to Ansible Galaxy.')
publish_parser.set_defaults(func=self.execute_publish)
publish_parser.add_argument('args', metavar='collection_path',
help='The path to the collection tarball to publish.')
publish_parser.add_argument('--no-wait', dest='wait', action='store_false', default=True,
help="Don't wait for import validation results.")
publish_parser.add_argument('--import-timeout', dest='import_timeout', type=int, default=0,
help="The time to wait for the collection import process to finish.")
def post_process_args(self, options):
options = super(GalaxyCLI, self).post_process_args(options)
setattr(options, 'validate_certs', (None if options.ignore_certs is None else not options.ignore_certs))
setattr(options, 'resolved_validate_certs', (options.validate_certs if options.validate_certs is not None else not C.GALAXY_IGNORE_CERTS))
display.verbosity = options.verbosity
return options
def run(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
super(GalaxyCLI, self).run()
self.galaxy = Galaxy()
def server_config_def(section, key, required, option_type):
config_def = {
'description': 'The %s of the %s Galaxy server' % (key, section),
'ini': [
{
'section': 'galaxy_server.%s' % section,
'key': key,
}
],
'env': [
{'name': 'ANSIBLE_GALAXY_SERVER_%s_%s' % (section.upper(), key.upper())},
],
'required': required,
'type': option_type,
}
if key in SERVER_ADDITIONAL:
config_def.update(SERVER_ADDITIONAL[key])
return config_def
galaxy_options = {}
for optional_key in ['clear_response_cache', 'no_cache']:
if optional_key in context.CLIARGS:
galaxy_options[optional_key] = context.CLIARGS[optional_key]
config_servers = []
server_list = [s for s in C.GALAXY_SERVER_LIST or [] if s]
for server_priority, server_key in enumerate(server_list, start=1):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
config_dict = dict((k, server_config_def(server_key, k, req, ensure_type)) for k, req, ensure_type in SERVER_DEF)
defs = AnsibleLoader(yaml_dump(config_dict)).get_single_data()
C.config.initialize_plugin_configuration_definitions('galaxy_server', server_key, defs)
server_options = C.config.get_plugin_options('galaxy_server', server_key)
auth_url = server_options.pop('auth_url')
client_id = server_options.pop('client_id')
token_val = server_options['token'] or NoTokenSentinel
username = server_options['username']
api_version = server_options.pop('api_version')
if server_options['validate_certs'] is None:
server_options['validate_certs'] = context.CLIARGS['resolved_validate_certs']
validate_certs = server_options['validate_certs']
if api_version:
display.warning(
f'The specified "api_version" configuration for the galaxy server "{server_key}" is '
'not a public configuration, and may be removed at any time without warning.'
)
server_options['available_api_versions'] = {'v%s' % api_version: '/v%s' % api_version}
server_options['token'] = None
if username:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
server_options['token'] = BasicAuthToken(username, server_options['password'])
else:
if token_val:
if auth_url:
server_options['token'] = KeycloakToken(access_token=token_val,
auth_url=auth_url,
validate_certs=validate_certs,
client_id=client_id)
else:
server_options['token'] = GalaxyToken(token=token_val)
server_options.update(galaxy_options)
config_servers.append(GalaxyAPI(
self.galaxy, server_key,
priority=server_priority,
**server_options
))
cmd_server = context.CLIARGS['api_server']
if context.CLIARGS['api_version']:
api_version = context.CLIARGS['api_version']
display.warning(
'The --api-version is not a public argument, and may be removed at any time without warning.'
)
galaxy_options['available_api_versions'] = {'v%s' % api_version: '/v%s' % api_version}
cmd_token = GalaxyToken(token=context.CLIARGS['api_key'])
validate_certs = context.CLIARGS['resolved_validate_certs']
default_server_timeout = context.CLIARGS['timeout'] if context.CLIARGS['timeout'] is not None else C.GALAXY_SERVER_TIMEOUT
if cmd_server:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
config_server = next((s for s in config_servers if s.name == cmd_server), None)
if config_server:
self.api_servers.append(config_server)
else:
self.api_servers.append(GalaxyAPI(
self.galaxy, 'cmd_arg', cmd_server, token=cmd_token,
priority=len(config_servers) + 1,
validate_certs=validate_certs,
timeout=default_server_timeout,
**galaxy_options
))
else:
self.api_servers = config_servers
if len(self.api_servers) == 0:
self.api_servers.append(GalaxyAPI(
self.galaxy, 'default', C.GALAXY_SERVER, token=cmd_token,
priority=0,
validate_certs=validate_certs,
timeout=default_server_timeout,
**galaxy_options
))
self.lazy_role_api = RoleDistributionServer(None, self.api_servers)
return context.CLIARGS['func']()
@property
def api(self):
return self.lazy_role_api.api
def _get_default_collection_path(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
return C.COLLECTIONS_PATHS[0]
def _parse_requirements_file(self, requirements_file, allow_old_format=True, artifacts_manager=None, validate_signature_options=True):
"""
Parses an Ansible requirement.yml file and returns all the roles and/or collections defined in it. There are 2
requirements file format:
# v1 (roles only)
- src: The source of the role, required if include is not set. Can be Galaxy role name, URL to a SCM repo or tarball.
name: Downloads the role to the specified name, defaults to Galaxy name from Galaxy or name of repo if src is a URL.
scm: If src is a URL, specify the SCM. Only git or hd are supported and defaults ot git.
version: The version of the role to download. Can also be tag, commit, or branch name and defaults to master.
include: Path to additional requirements.yml files.
# v2 (roles and collections)
---
roles:
# Same as v1 format just under the roles key
collections:
- namespace.collection
- name: namespace.collection
version: version identifier, multiple identifiers are separated by ','
source: the URL or a predefined source name that relates to C.GALAXY_SERVER_LIST
type: git|file|url|galaxy
:param requirements_file: The path to the requirements file.
:param allow_old_format: Will fail if a v1 requirements file is found and this is set to False.
:param artifacts_manager: Artifacts manager.
:return: a dict containing roles and collections to found in the requirements file.
"""
requirements = {
'roles': [],
'collections': [],
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
}
b_requirements_file = to_bytes(requirements_file, errors='surrogate_or_strict')
if not os.path.exists(b_requirements_file):
raise AnsibleError("The requirements file '%s' does not exist." % to_native(requirements_file))
display.vvv("Reading requirement file at '%s'" % requirements_file)
with open(b_requirements_file, 'rb') as req_obj:
try:
file_requirements = yaml_load(req_obj)
except YAMLError as err:
raise AnsibleError(
"Failed to parse the requirements yml at '%s' with the following error:\n%s"
% (to_native(requirements_file), to_native(err)))
if file_requirements is None:
raise AnsibleError("No requirements found in file '%s'" % to_native(requirements_file))
def parse_role_req(requirement):
if "include" not in requirement:
role = RoleRequirement.role_yaml_parse(requirement)
display.vvv("found role %s in yaml file" % to_text(role))
if "name" not in role and "src" not in role:
raise AnsibleError("Must specify name or src for role")
return [GalaxyRole(self.galaxy, self.lazy_role_api, **role)]
else:
b_include_path = to_bytes(requirement["include"], errors="surrogate_or_strict")
if not os.path.isfile(b_include_path):
raise AnsibleError("Failed to find include requirements file '%s' in '%s'"
% (to_native(b_include_path), to_native(requirements_file)))
with open(b_include_path, 'rb') as f_include:
try:
return [GalaxyRole(self.galaxy, self.lazy_role_api, **r) for r in
(RoleRequirement.role_yaml_parse(i) for i in yaml_load(f_include))]
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
except Exception as e:
raise AnsibleError("Unable to load data from include requirements file: %s %s"
% (to_native(requirements_file), to_native(e)))
if isinstance(file_requirements, list):
if not allow_old_format:
raise AnsibleError("Expecting requirements file to be a dict with the key 'collections' that contains "
"a list of collections to install")
for role_req in file_requirements:
requirements['roles'] += parse_role_req(role_req)
elif isinstance(file_requirements, dict):
extra_keys = set(file_requirements.keys()).difference(set(['roles', 'collections']))
if extra_keys:
raise AnsibleError("Expecting only 'roles' and/or 'collections' as base keys in the requirements "
"file. Found: %s" % (to_native(", ".join(extra_keys))))
for role_req in file_requirements.get('roles') or []:
requirements['roles'] += parse_role_req(role_req)
requirements['collections'] = [
Requirement.from_requirement_dict(
self._init_coll_req_dict(collection_req),
artifacts_manager,
validate_signature_options,
)
for collection_req in file_requirements.get('collections') or []
]
else:
raise AnsibleError(f"Expecting requirements yaml to be a list or dictionary but got {type(file_requirements).__name__}")
return requirements
def _init_coll_req_dict(self, coll_req):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
if not isinstance(coll_req, dict):
return {'name': coll_req}
if (
'name' not in coll_req or
not coll_req.get('source') or
coll_req.get('type', 'galaxy') != 'galaxy'
):
return coll_req
coll_req['source'] = next(
iter(
srvr for srvr in self.api_servers
if coll_req['source'] in {srvr.name, srvr.api_server}
),
GalaxyAPI(
self.galaxy,
'explicit_requirement_{name!s}'.format(
name=coll_req['name'],
),
coll_req['source'],
validate_certs=context.CLIARGS['resolved_validate_certs'],
),
)
return coll_req
@staticmethod
def exit_without_ignore(rc=1):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
"""
Exits with the specified return code unless the
option --ignore-errors was specified
"""
if not context.CLIARGS['ignore_errors']:
raise AnsibleError('- you can use --ignore-errors to skip failed roles and finish processing the list.')
@staticmethod
def _display_role_info(role_info):
text = [u"", u"Role: %s" % to_text(role_info['name'])]
galaxy_info = role_info.get('galaxy_info', {})
description = role_info.get('description', galaxy_info.get('description', ''))
text.append(u"\tdescription: %s" % description)
for k in sorted(role_info.keys()):
if k in GalaxyCLI.SKIP_INFO_KEYS:
continue
if isinstance(role_info[k], dict):
text.append(u"\t%s:" % (k))
for key in sorted(role_info[k].keys()):
if key in GalaxyCLI.SKIP_INFO_KEYS:
continue
text.append(u"\t\t%s: %s" % (key, role_info[k][key]))
else:
text.append(u"\t%s: %s" % (k, role_info[k]))
text.append(u"")
return u'\n'.join(text)
@staticmethod
def _resolve_path(path):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
return os.path.abspath(os.path.expanduser(os.path.expandvars(path)))
@staticmethod
def _get_skeleton_galaxy_yml(template_path, inject_data):
with open(to_bytes(template_path, errors='surrogate_or_strict'), 'rb') as template_obj:
meta_template = to_text(template_obj.read(), errors='surrogate_or_strict')
galaxy_meta = get_collections_galaxy_meta_info()
required_config = []
optional_config = []
for meta_entry in galaxy_meta:
config_list = required_config if meta_entry.get('required', False) else optional_config
value = inject_data.get(meta_entry['key'], None)
if not value:
meta_type = meta_entry.get('type', 'str')
if meta_type == 'str':
value = ''
elif meta_type == 'list':
value = []
elif meta_type == 'dict':
value = {}
meta_entry['value'] = value
config_list.append(meta_entry)
link_pattern = re.compile(r"L\(([^)]+),\s+([^)]+)\)")
const_pattern = re.compile(r"C\(([^)]+)\)")
def comment_ify(v):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
if isinstance(v, list):
v = ". ".join([l.rstrip('.') for l in v])
v = link_pattern.sub(r"\1 <\2>", v)
v = const_pattern.sub(r"'\1'", v)
return textwrap.fill(v, width=117, initial_indent="# ", subsequent_indent="# ", break_on_hyphens=False)
loader = DataLoader()
templar = Templar(loader, variables={'required_config': required_config, 'optional_config': optional_config})
templar.environment.filters['comment_ify'] = comment_ify
meta_value = templar.template(meta_template)
return meta_value
def _require_one_of_collections_requirements(
self, collections, requirements_file,
signatures=None,
artifacts_manager=None,
):
if collections and requirements_file:
raise AnsibleError("The positional collection_name arg and --requirements-file are mutually exclusive.")
elif not collections and not requirements_file:
raise AnsibleError("You must specify a collection name or a requirements file.")
elif requirements_file:
if signatures is not None:
raise AnsibleError(
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
"The --signatures option and --requirements-file are mutually exclusive. "
"Use the --signatures with positional collection_name args or provide a "
"'signatures' key for requirements in the --requirements-file."
)
requirements_file = GalaxyCLI._resolve_path(requirements_file)
requirements = self._parse_requirements_file(
requirements_file,
allow_old_format=False,
artifacts_manager=artifacts_manager,
)
else:
requirements = {
'collections': [
Requirement.from_string(coll_input, artifacts_manager, signatures)
for coll_input in collections
],
'roles': [],
}
return requirements
def execute_role(self):
"""
Perform the action on an Ansible Galaxy role. Must be combined with a further action like delete/install/init
as listed below.
"""
pass
def execute_collection(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
"""
Perform the action on an Ansible Galaxy collection. Must be combined with a further action like init/install as
listed below.
"""
pass
def execute_build(self):
"""
Build an Ansible Galaxy collection artifact that can be stored in a central repository like Ansible Galaxy.
By default, this command builds from the current working directory. You can optionally pass in the
collection input path (where the ``galaxy.yml`` file is).
"""
force = context.CLIARGS['force']
output_path = GalaxyCLI._resolve_path(context.CLIARGS['output_path'])
b_output_path = to_bytes(output_path, errors='surrogate_or_strict')
if not os.path.exists(b_output_path):
os.makedirs(b_output_path)
elif os.path.isfile(b_output_path):
raise AnsibleError("- the output collection directory %s is a file - aborting" % to_native(output_path))
for collection_path in context.CLIARGS['args']:
collection_path = GalaxyCLI._resolve_path(collection_path)
build_collection(
to_text(collection_path, errors='surrogate_or_strict'),
to_text(output_path, errors='surrogate_or_strict'),
force,
)
@with_collection_artifacts_manager
def execute_download(self, artifacts_manager=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
"""Download collections and their dependencies as a tarball for an offline install."""
collections = context.CLIARGS['args']
no_deps = context.CLIARGS['no_deps']
download_path = context.CLIARGS['download_path']
requirements_file = context.CLIARGS['requirements']
if requirements_file:
requirements_file = GalaxyCLI._resolve_path(requirements_file)
requirements = self._require_one_of_collections_requirements(
collections, requirements_file,
artifacts_manager=artifacts_manager,
)['collections']
download_path = GalaxyCLI._resolve_path(download_path)
b_download_path = to_bytes(download_path, errors='surrogate_or_strict')
if not os.path.exists(b_download_path):
os.makedirs(b_download_path)
download_collections(
requirements, download_path, self.api_servers, no_deps,
context.CLIARGS['allow_pre_release'],
artifacts_manager=artifacts_manager,
)
return 0
def execute_init(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
"""
Creates the skeleton framework of a role or collection that complies with the Galaxy metadata format.
Requires a role or collection name. The collection name must be in the format ``<namespace>.<collection>``.
"""
galaxy_type = context.CLIARGS['type']
init_path = context.CLIARGS['init_path']
force = context.CLIARGS['force']
obj_skeleton = context.CLIARGS['{0}_skeleton'.format(galaxy_type)]
obj_name = context.CLIARGS['{0}_name'.format(galaxy_type)]
inject_data = dict(
description='your {0} description'.format(galaxy_type),
ansible_plugin_list_dir=get_versioned_doclink('plugins/plugins.html'),
)
if galaxy_type == 'role':
inject_data.update(dict(
author='your name',
company='your company (optional)',
license='license (GPL-2.0-or-later, MIT, etc)',
role_name=obj_name,
role_type=context.CLIARGS['role_type'],
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
issue_tracker_url='http://example.com/issue/tracker',
repository_url='http://example.com/repository',
documentation_url='http://docs.example.com',
homepage_url='http://example.com',
min_ansible_version=ansible_version[:3],
dependencies=[],
))
skeleton_ignore_expressions = C.GALAXY_ROLE_SKELETON_IGNORE
obj_path = os.path.join(init_path, obj_name)
elif galaxy_type == 'collection':
namespace, collection_name = obj_name.split('.', 1)
inject_data.update(dict(
namespace=namespace,
collection_name=collection_name,
version='1.0.0',
readme='README.md',
authors=['your name <[email protected]>'],
license=['GPL-2.0-or-later'],
repository='http://example.com/repository',
documentation='http://docs.example.com',
homepage='http://example.com',
issues='http://example.com/issue/tracker',
build_ignore=[],
))
skeleton_ignore_expressions = C.GALAXY_COLLECTION_SKELETON_IGNORE
obj_path = os.path.join(init_path, namespace, collection_name)
b_obj_path = to_bytes(obj_path, errors='surrogate_or_strict')
if os.path.exists(b_obj_path):
if os.path.isfile(obj_path):
raise AnsibleError("- the path %s already exists, but is a file - aborting" % to_native(obj_path))
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
elif not force:
raise AnsibleError("- the directory %s already exists. "
"You can use --force to re-initialize this directory,\n"
"however it will reset any main.yml files that may have\n"
"been modified there already." % to_native(obj_path))
for root, dirs, files in os.walk(b_obj_path, topdown=True):
for old_dir in dirs:
path = os.path.join(root, old_dir)
shutil.rmtree(path)
for old_file in files:
path = os.path.join(root, old_file)
os.unlink(path)
if obj_skeleton is not None:
own_skeleton = False
else:
own_skeleton = True
obj_skeleton = self.galaxy.default_role_skeleton_path
skeleton_ignore_expressions = ['^.*/.git_keep$']
obj_skeleton = os.path.expanduser(obj_skeleton)
skeleton_ignore_re = [re.compile(x) for x in skeleton_ignore_expressions]
if not os.path.exists(obj_skeleton):
raise AnsibleError("- the skeleton path '{0}' does not exist, cannot init {1}".format(
to_native(obj_skeleton), galaxy_type)
)
loader = DataLoader()
templar = Templar(loader, variables=inject_data)
if not os.path.exists(b_obj_path):
os.makedirs(b_obj_path)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
for root, dirs, files in os.walk(obj_skeleton, topdown=True):
rel_root = os.path.relpath(root, obj_skeleton)
rel_dirs = rel_root.split(os.sep)
rel_root_dir = rel_dirs[0]
if galaxy_type == 'collection':
in_templates_dir = rel_root_dir in ['playbooks', 'roles'] and 'templates' in rel_dirs
else:
in_templates_dir = rel_root_dir == 'templates'
dirs[:] = [d for d in dirs if not any(r.match(d) for r in skeleton_ignore_re)]
for f in files:
filename, ext = os.path.splitext(f)
if any(r.match(os.path.join(rel_root, f)) for r in skeleton_ignore_re):
continue
if galaxy_type == 'collection' and own_skeleton and rel_root == '.' and f == 'galaxy.yml.j2':
template_data = inject_data.copy()
template_data['name'] = template_data.pop('collection_name')
meta_value = GalaxyCLI._get_skeleton_galaxy_yml(os.path.join(root, rel_root, f), template_data)
b_dest_file = to_bytes(os.path.join(obj_path, rel_root, filename), errors='surrogate_or_strict')
with open(b_dest_file, 'wb') as galaxy_obj:
galaxy_obj.write(to_bytes(meta_value, errors='surrogate_or_strict'))
elif ext == ".j2" and not in_templates_dir:
src_template = os.path.join(root, f)
dest_file = os.path.join(obj_path, rel_root, filename)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
template_data = to_text(loader._get_file_contents(src_template)[0], errors='surrogate_or_strict')
b_rendered = to_bytes(templar.template(template_data), errors='surrogate_or_strict')
with open(dest_file, 'wb') as df:
df.write(b_rendered)
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)
for d in dirs:
b_dir_path = to_bytes(os.path.join(obj_path, rel_root, d), errors='surrogate_or_strict')
if os.path.exists(b_dir_path):
continue
b_src_dir = to_bytes(os.path.join(root, d), errors='surrogate_or_strict')
if os.path.islink(b_src_dir):
shutil.copyfile(b_src_dir, b_dir_path, follow_symlinks=False)
else:
os.makedirs(b_dir_path)
display.display("- %s %s was created successfully" % (galaxy_type.title(), obj_name))
def execute_info(self):
"""
prints out detailed information about an installed role as well as info available from the galaxy API.
"""
roles_path = context.CLIARGS['roles_path']
data = ''
for role in context.CLIARGS['args']:
role_info = {'path': roles_path}
gr = GalaxyRole(self.galaxy, self.lazy_role_api, role)
install_info = gr.install_info
if install_info:
if 'version' in install_info:
install_info['installed_version'] = install_info['version']
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
del install_info['version']
role_info.update(install_info)
if not context.CLIARGS['offline']:
remote_data = None
try:
remote_data = self.api.lookup_role_by_name(role, False)
except GalaxyError as e:
if e.http_code == 400 and 'Bad Request' in e.message:
data = u"- the role %s was not found" % role
break
raise AnsibleError("Unable to find info about '%s': %s" % (role, e))
if remote_data:
role_info.update(remote_data)
else:
data = u"- the role %s was not found" % role
break
elif context.CLIARGS['offline'] and not gr._exists:
data = u"- the role %s was not found" % role
break
if gr.metadata:
role_info.update(gr.metadata)
req = RoleRequirement()
role_spec = req.role_yaml_parse({'role': role})
if role_spec:
role_info.update(role_spec)
data += self._display_role_info(role_info)
self.pager(data)
@with_collection_artifacts_manager
def execute_verify(self, artifacts_manager=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
"""Compare checksums with the collection(s) found on the server and the installed copy. This does not verify dependencies."""
collections = context.CLIARGS['args']
search_paths = AnsibleCollectionConfig.collection_paths
ignore_errors = context.CLIARGS['ignore_errors']
local_verify_only = context.CLIARGS['offline']
requirements_file = context.CLIARGS['requirements']
signatures = context.CLIARGS['signatures']
if signatures is not None:
signatures = list(signatures)
requirements = self._require_one_of_collections_requirements(
collections, requirements_file,
signatures=signatures,
artifacts_manager=artifacts_manager,
)['collections']
resolved_paths = [validate_collection_path(GalaxyCLI._resolve_path(path)) for path in search_paths]
results = verify_collections(
requirements, resolved_paths,
self.api_servers, ignore_errors,
local_verify_only=local_verify_only,
artifacts_manager=artifacts_manager,
)
if any(result for result in results if not result.success):
return 1
return 0
@with_collection_artifacts_manager
def execute_install(self, artifacts_manager=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
"""
Install one or more roles(``ansible-galaxy role install``), or one or more collections(``ansible-galaxy collection install``).
You can pass in a list (roles or collections) or use the file
option listed below (these are mutually exclusive). If you pass in a list, it
can be a name (which will be downloaded via the galaxy API and github), or it can be a local tar archive file.
"""
install_items = context.CLIARGS['args']
requirements_file = context.CLIARGS['requirements']
collection_path = None
signatures = context.CLIARGS.get('signatures')
if signatures is not None:
signatures = list(signatures)
if requirements_file:
requirements_file = GalaxyCLI._resolve_path(requirements_file)
two_type_warning = "The requirements file '%s' contains {0}s which will be ignored. To install these {0}s " \
"run 'ansible-galaxy {0} install -r' or to install both at the same time run " \
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
"'ansible-galaxy install -r' without a custom install path." % to_text(requirements_file)
collection_requirements = []
role_requirements = []
if context.CLIARGS['type'] == 'collection':
collection_path = GalaxyCLI._resolve_path(context.CLIARGS['collections_path'])
requirements = self._require_one_of_collections_requirements(
install_items, requirements_file,
signatures=signatures,
artifacts_manager=artifacts_manager,
)
collection_requirements = requirements['collections']
if requirements['roles']:
display.vvv(two_type_warning.format('role'))
else:
if not install_items and requirements_file is None:
raise AnsibleOptionsError("- you must specify a user/role name or a roles file")
if requirements_file:
if not (requirements_file.endswith('.yaml') or requirements_file.endswith('.yml')):
raise AnsibleError("Invalid role requirements file, it must end with a .yml or .yaml extension")
galaxy_args = self._raw_args
will_install_collections = self._implicit_role and '-p' not in galaxy_args and '--roles-path' not in galaxy_args
requirements = self._parse_requirements_file(
requirements_file,
artifacts_manager=artifacts_manager,
validate_signature_options=will_install_collections,
)
role_requirements = requirements['roles']
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
if requirements['collections'] and (not self._implicit_role or '-p' in galaxy_args or
'--roles-path' in galaxy_args):
display_func = display.warning if self._implicit_role else display.vvv
display_func(two_type_warning.format('collection'))
else:
collection_path = self._get_default_collection_path()
collection_requirements = requirements['collections']
else:
for rname in context.CLIARGS['args']:
role = RoleRequirement.role_yaml_parse(rname.strip())
role_requirements.append(GalaxyRole(self.galaxy, self.lazy_role_api, **role))
if not role_requirements and not collection_requirements:
display.display("Skipping install, no requirements found")
return
if role_requirements:
display.display("Starting galaxy role install process")
self._execute_install_role(role_requirements)
if collection_requirements:
display.display("Starting galaxy collection install process")
self._execute_install_collection(
collection_requirements, collection_path,
artifacts_manager=artifacts_manager,
)
def _execute_install_collection(
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
self, requirements, path, artifacts_manager,
):
force = context.CLIARGS['force']
ignore_errors = context.CLIARGS['ignore_errors']
no_deps = context.CLIARGS['no_deps']
force_with_deps = context.CLIARGS['force_with_deps']
try:
disable_gpg_verify = context.CLIARGS['disable_gpg_verify']
except KeyError:
if self._implicit_role:
raise AnsibleError(
'Unable to properly parse command line arguments. Please use "ansible-galaxy collection install" '
'instead of "ansible-galaxy install".'
)
raise
allow_pre_release = context.CLIARGS.get('allow_pre_release', False)
upgrade = context.CLIARGS.get('upgrade', False)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
collections_path = C.COLLECTIONS_PATHS
managed_paths = set(validate_collection_path(p) for p in C.COLLECTIONS_PATHS)
read_req_paths = set(validate_collection_path(p) for p in AnsibleCollectionConfig.collection_paths)
unexpected_path = C.GALAXY_COLLECTIONS_PATH_WARNING and not any(p.startswith(path) for p in managed_paths)
if unexpected_path and any(p.startswith(path) for p in read_req_paths):
display.warning(
f"The specified collections path '{path}' appears to be part of the pip Ansible package. "
"Managing these directly with ansible-galaxy could break the Ansible package. "
"Install collections to a configured collections path, which will take precedence over "
"collections found in the PYTHONPATH."
)
elif unexpected_path:
display.warning("The specified collections path '%s' is not part of the configured Ansible "
"collections paths '%s'. The installed collection will not be picked up in an Ansible "
"run, unless within a playbook-adjacent collections directory." % (to_text(path), to_text(":".join(collections_path))))
output_path = validate_collection_path(path)
b_output_path = to_bytes(output_path, errors='surrogate_or_strict')
if not os.path.exists(b_output_path):
os.makedirs(b_output_path)
install_collections(
requirements, output_path, self.api_servers, ignore_errors,
no_deps, force, force_with_deps, upgrade,
allow_pre_release=allow_pre_release,
artifacts_manager=artifacts_manager,
disable_gpg_verify=disable_gpg_verify,
offline=context.CLIARGS.get('offline', False),
read_requirement_paths=read_req_paths,
)
return 0
def _execute_install_role(self, requirements):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
role_file = context.CLIARGS['requirements']
no_deps = context.CLIARGS['no_deps']
force_deps = context.CLIARGS['force_with_deps']
force = context.CLIARGS['force'] or force_deps
for role in requirements:
if role_file and context.CLIARGS['args'] and role.name not in context.CLIARGS['args']:
display.vvv('Skipping role %s' % role.name)
continue
display.vvv('Processing role %s ' % role.name)
if role.install_info is not None:
if role.install_info['version'] != role.version or force:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
if force:
display.display('- changing role %s from %s to %s' %
(role.name, role.install_info['version'], role.version or "unspecified"))
role.remove()
else:
display.warning('- %s (%s) is already installed - use --force to change version to %s' %
(role.name, role.install_info['version'], role.version or "unspecified"))
continue
else:
if not force:
display.display('- %s is already installed, skipping.' % str(role))
continue
try:
installed = role.install()
except AnsibleError as e:
display.warning(u"- %s was NOT installed successfully: %s " % (role.name, to_text(e)))
self.exit_without_ignore()
continue
if not no_deps and installed:
if not role.metadata:
display.warning("Meta file %s is empty. Skipping dependencies." % role.path)
else:
role_dependencies = role.metadata_dependencies + role.requirements
for dep in role_dependencies:
display.debug('Installing dep %s' % dep)
dep_req = RoleRequirement()
dep_info = dep_req.role_yaml_parse(dep)
dep_role = GalaxyRole(self.galaxy, self.lazy_role_api, **dep_info)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
if '.' not in dep_role.name and '.' not in dep_role.src and dep_role.scm is None:
continue
if dep_role.install_info is None:
if dep_role not in requirements:
display.display('- adding dependency: %s' % to_text(dep_role))
requirements.append(dep_role)
else:
display.display('- dependency %s already pending installation.' % dep_role.name)
else:
if dep_role.install_info['version'] != dep_role.version:
if force_deps:
display.display('- changing dependent role %s from %s to %s' %
(dep_role.name, dep_role.install_info['version'], dep_role.version or "unspecified"))
dep_role.remove()
requirements.append(dep_role)
else:
display.warning('- dependency %s (%s) from role %s differs from already installed version (%s), skipping' %
(to_text(dep_role), dep_role.version, role.name, dep_role.install_info['version']))
else:
if force_deps:
requirements.append(dep_role)
else:
display.display('- dependency %s is already installed, skipping.' % dep_role.name)
if not installed:
display.warning("- %s was NOT installed successfully." % role.name)
self.exit_without_ignore()
return 0
def execute_remove(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
"""
removes the list of roles passed as arguments from the local system.
"""
if not context.CLIARGS['args']:
raise AnsibleOptionsError('- you must specify at least one role to remove.')
for role_name in context.CLIARGS['args']:
role = GalaxyRole(self.galaxy, self.api, role_name)
try:
if role.remove():
display.display('- successfully removed %s' % role_name)
else:
display.display('- %s is not installed, skipping.' % role_name)
except Exception as e:
raise AnsibleError("Failed to remove role %s: %s" % (role_name, to_native(e)))
return 0
def execute_list(self):
"""
List installed collections or roles
"""
if context.CLIARGS['type'] == 'role':
self.execute_list_role()
elif context.CLIARGS['type'] == 'collection':
self.execute_list_collection()
def execute_list_role(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
"""
List all roles installed on the local system or a specific role
"""
path_found = False
role_found = False
warnings = []
roles_search_paths = context.CLIARGS['roles_path']
role_name = context.CLIARGS['role']
for path in roles_search_paths:
role_path = GalaxyCLI._resolve_path(path)
if os.path.isdir(path):
path_found = True
else:
warnings.append("- the configured path {0} does not exist.".format(path))
continue
if role_name:
gr = GalaxyRole(self.galaxy, self.lazy_role_api, role_name, path=os.path.join(role_path, role_name))
if os.path.isdir(gr.path):
role_found = True
display.display('# %s' % os.path.dirname(gr.path))
_display_role(gr)
break
warnings.append("- the role %s was not found" % role_name)
else:
if not os.path.exists(role_path):
warnings.append("- the configured path %s does not exist." % role_path)
continue
if not os.path.isdir(role_path):
warnings.append("- the configured path %s, exists, but it is not a directory." % role_path)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
continue
display.display('# %s' % role_path)
path_files = os.listdir(role_path)
for path_file in path_files:
gr = GalaxyRole(self.galaxy, self.lazy_role_api, path_file, path=path)
if gr.metadata:
_display_role(gr)
if role_found and role_name:
warnings = []
for w in warnings:
display.warning(w)
if not path_found:
raise AnsibleOptionsError(
"- None of the provided paths were usable. Please specify a valid path with --{0}s-path".format(context.CLIARGS['type'])
)
return 0
@with_collection_artifacts_manager
def execute_list_collection(self, artifacts_manager=None):
"""
List all collections installed on the local system
:param artifacts_manager: Artifacts manager.
"""
if artifacts_manager is not None:
artifacts_manager.require_build_metadata = False
output_format = context.CLIARGS['output_format']
collection_name = context.CLIARGS['collection']
default_collections_path = set(C.COLLECTIONS_PATHS)
collections_search_paths = (
set(context.CLIARGS['collections_path'] or []) | default_collections_path | set(AnsibleCollectionConfig.collection_paths)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
)
collections_in_paths = {}
warnings = []
path_found = False
collection_found = False
namespace_filter = None
collection_filter = None
if collection_name:
validate_collection_name(collection_name)
namespace_filter, collection_filter = collection_name.split('.')
collections = list(find_existing_collections(
list(collections_search_paths),
artifacts_manager,
namespace_filter=namespace_filter,
collection_filter=collection_filter,
dedupe=False
))
seen = set()
fqcn_width, version_width = _get_collection_widths(collections)
for collection in sorted(collections, key=lambda c: c.src):
collection_found = True
collection_path = pathlib.Path(to_text(collection.src)).parent.parent.as_posix()
if output_format in {'yaml', 'json'}:
collections_in_paths.setdefault(collection_path, {})
collections_in_paths[collection_path][collection.fqcn] = {'version': collection.ver}
else:
if collection_path not in seen:
_display_header(
collection_path,
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
'Collection',
'Version',
fqcn_width,
version_width
)
seen.add(collection_path)
_display_collection(collection, fqcn_width, version_width)
path_found = False
for path in collections_search_paths:
if not os.path.exists(path):
if path in default_collections_path:
continue
warnings.append("- the configured path {0} does not exist.".format(path))
elif os.path.exists(path) and not os.path.isdir(path):
warnings.append("- the configured path {0}, exists, but it is not a directory.".format(path))
else:
path_found = True
if collection_found and collection_name:
warnings = []
for w in warnings:
display.warning(w)
if not collections and not path_found:
raise AnsibleOptionsError(
"- None of the provided paths were usable. Please specify a valid path with --{0}s-path".format(context.CLIARGS['type'])
)
if output_format == 'json':
display.display(json.dumps(collections_in_paths))
elif output_format == 'yaml':
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
display.display(yaml_dump(collections_in_paths))
return 0
def execute_publish(self):
"""
Publish a collection into Ansible Galaxy. Requires the path to the collection tarball to publish.
"""
collection_path = GalaxyCLI._resolve_path(context.CLIARGS['args'])
wait = context.CLIARGS['wait']
timeout = context.CLIARGS['import_timeout']
publish_collection(collection_path, self.api, wait, timeout)
def execute_search(self):
''' searches for roles on the Ansible Galaxy server'''
page_size = 1000
search = None
if context.CLIARGS['args']:
search = '+'.join(context.CLIARGS['args'])
if not search and not context.CLIARGS['platforms'] and not context.CLIARGS['galaxy_tags'] and not context.CLIARGS['author']:
raise AnsibleError("Invalid query. At least one search term, platform, galaxy tag or author must be provided.")
response = self.api.search_roles(search, platforms=context.CLIARGS['platforms'],
tags=context.CLIARGS['galaxy_tags'], author=context.CLIARGS['author'], page_size=page_size)
if response['count'] == 0:
display.warning("No roles match your search.")
return 0
data = [u'']
if response['count'] > page_size:
data.append(u"Found %d roles matching your search. Showing first %s." % (response['count'], page_size))
else:
data.append(u"Found %d roles matching your search:" % response['count'])
max_len = []
for role in response['results']:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
max_len.append(len(role['username'] + '.' + role['name']))
name_len = max(max_len)
format_str = u" %%-%ds %%s" % name_len
data.append(u'')
data.append(format_str % (u"Name", u"Description"))
data.append(format_str % (u"----", u"-----------"))
for role in response['results']:
data.append(format_str % (u'%s.%s' % (role['username'], role['name']), role['description']))
data = u'\n'.join(data)
self.pager(data)
return 0
def execute_import(self):
""" used to import a role into Ansible Galaxy """
colors = {
'INFO': 'normal',
'WARNING': C.COLOR_WARN,
'ERROR': C.COLOR_ERROR,
'SUCCESS': C.COLOR_OK,
'FAILED': C.COLOR_ERROR,
}
github_user = to_text(context.CLIARGS['github_user'], errors='surrogate_or_strict')
github_repo = to_text(context.CLIARGS['github_repo'], errors='surrogate_or_strict')
if context.CLIARGS['check_status']:
task = self.api.get_import_task(github_user=github_user, github_repo=github_repo)
else:
task = self.api.create_import_task(github_user, github_repo,
reference=context.CLIARGS['reference'],
role_name=context.CLIARGS['role_name'])
if len(task) > 1:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
display.display("WARNING: More than one Galaxy role associated with Github repo %s/%s." % (github_user, github_repo),
color='yellow')
display.display("The following Galaxy roles are being updated:" + u'\n', color=C.COLOR_CHANGED)
for t in task:
display.display('%s.%s' % (t['summary_fields']['role']['namespace'], t['summary_fields']['role']['name']), color=C.COLOR_CHANGED)
display.display(u'\nTo properly namespace this role, remove each of the above and re-import %s/%s from scratch' % (github_user, github_repo),
color=C.COLOR_CHANGED)
return 0
display.display("Successfully submitted import request %d" % task[0]['id'])
if not context.CLIARGS['wait']:
display.display("Role name: %s" % task[0]['summary_fields']['role']['name'])
display.display("Repo: %s/%s" % (task[0]['github_user'], task[0]['github_repo']))
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
def execute_setup(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
""" Setup an integration from Github or Travis for Ansible Galaxy roles"""
if context.CLIARGS['setup_list']:
secrets = self.api.list_secrets()
if len(secrets) == 0:
display.display("No integrations found.")
return 0
display.display(u'\n' + "ID Source Repo", color=C.COLOR_OK)
display.display("---------- ---------- ----------", color=C.COLOR_OK)
for secret in secrets:
display.display("%-10s %-10s %s/%s" % (secret['id'], secret['source'], secret['github_user'],
secret['github_repo']), color=C.COLOR_OK)
return 0
if context.CLIARGS['remove_id']:
self.api.remove_secret(context.CLIARGS['remove_id'])
display.display("Secret removed. Integrations using this secret will not longer work.", color=C.COLOR_OK)
return 0
source = context.CLIARGS['source']
github_user = context.CLIARGS['github_user']
github_repo = context.CLIARGS['github_repo']
secret = context.CLIARGS['secret']
resp = self.api.add_secret(source, github_user, github_repo, secret)
display.display("Added integration for %s %s/%s" % (resp['source'], resp['github_user'], resp['github_repo']))
return 0
def execute_delete(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
lib/ansible/cli/galaxy.py
|
""" Delete a role from Ansible Galaxy. """
github_user = context.CLIARGS['github_user']
github_repo = context.CLIARGS['github_repo']
resp = self.api.delete_role(github_user, github_repo)
if len(resp['deleted_roles']) > 1:
display.display("Deleted the following roles:")
display.display("ID User Name")
display.display("------ --------------- ----------")
for role in resp['deleted_roles']:
display.display("%-8s %-15s %s" % (role.id, role.namespace, role.name))
display.display(resp['status'])
return 0
def main(args=None):
GalaxyCLI.cli_executor(args)
if __name__ == '__main__':
main()
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
test/units/galaxy/test_role_install.py
|
from __future__ import annotations
import os
import functools
import pytest
import tempfile
from io import StringIO
from ansible import context
from ansible.cli.galaxy import GalaxyCLI
from ansible.galaxy import api, role, Galaxy
from ansible.module_utils.common.text.converters import to_text
from ansible.utils import context_objects as co
def call_galaxy_cli(args):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
test/units/galaxy/test_role_install.py
|
orig = co.GlobalCLIArgs._Singleton__instance
co.GlobalCLIArgs._Singleton__instance = None
try:
GalaxyCLI(args=['ansible-galaxy', 'role'] + args).run()
finally:
co.GlobalCLIArgs._Singleton__instance = orig
@pytest.fixture(autouse='function')
def reset_cli_args():
co.GlobalCLIArgs._Singleton__instance = None
yield
co.GlobalCLIArgs._Singleton__instance = None
@pytest.fixture(autouse=True)
def galaxy_server():
context.CLIARGS._store = {'ignore_certs': False}
galaxy_api = api.GalaxyAPI(None, 'test_server', 'https://galaxy.ansible.com')
return galaxy_api
@pytest.fixture(autouse=True)
def init_role_dir(tmp_path_factory):
test_dir = to_text(tmp_path_factory.mktemp('test-ÅÑŚÌβŁÈ Roles Input'))
namespace = 'ansible_namespace'
role = 'role'
skeleton_path = os.path.join(os.path.dirname(os.path.split(__file__)[0]), 'cli', 'test_data', 'role_skeleton')
call_galaxy_cli(['init', '%s.%s' % (namespace, role), '-c', '--init-path', test_dir, '--role-skeleton', skeleton_path])
def mock_NamedTemporaryFile(mocker, **args):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
test/units/galaxy/test_role_install.py
|
mock_ntf = mocker.MagicMock()
mock_ntf.write = mocker.MagicMock()
mock_ntf.close = mocker.MagicMock()
mock_ntf.name = None
return mock_ntf
@pytest.fixture
def init_mock_temp_file(mocker, monkeypatch):
monkeypatch.setattr(tempfile, 'NamedTemporaryFile', functools.partial(mock_NamedTemporaryFile, mocker))
@pytest.fixture(autouse=True)
def mock_role_download_api(mocker, monkeypatch):
mock_role_api = mocker.MagicMock()
mock_role_api.side_effect = [
StringIO(u''),
]
monkeypatch.setattr(role, 'open_url', mock_role_api)
return mock_role_api
def test_role_download_github(init_mock_temp_file, mocker, galaxy_server, mock_role_download_api, monkeypatch):
mock_api = mocker.MagicMock()
mock_api.side_effect = [
StringIO(u'{"available_versions":{"v1":"v1/"}}'),
StringIO(u'{"results":[{"id":"123","github_user":"test_owner","github_repo": "test_role"}]}'),
StringIO(u'{"results":[{"name": "0.0.1"},{"name": "0.0.2"}]}'),
]
monkeypatch.setattr(api, 'open_url', mock_api)
role.GalaxyRole(Galaxy(), galaxy_server, 'test_owner.test_role', version="0.0.1").install()
assert mock_role_download_api.call_count == 1
assert mock_role_download_api.mock_calls[0][1][0] == 'https://github.com/test_owner/test_role/archive/0.0.1.tar.gz'
def test_role_download_github_default_version(init_mock_temp_file, mocker, galaxy_server, mock_role_download_api, monkeypatch):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
test/units/galaxy/test_role_install.py
|
mock_api = mocker.MagicMock()
mock_api.side_effect = [
StringIO(u'{"available_versions":{"v1":"v1/"}}'),
StringIO(u'{"results":[{"id":"123","github_user":"test_owner","github_repo": "test_role"}]}'),
StringIO(u'{"results":[{"name": "0.0.1"},{"name": "0.0.2"}]}'),
]
monkeypatch.setattr(api, 'open_url', mock_api)
role.GalaxyRole(Galaxy(), galaxy_server, 'test_owner.test_role').install()
assert mock_role_download_api.call_count == 1
assert mock_role_download_api.mock_calls[0][1][0] == 'https://github.com/test_owner/test_role/archive/0.0.2.tar.gz'
def test_role_download_github_no_download_url_for_version(init_mock_temp_file, mocker, galaxy_server, mock_role_download_api, monkeypatch):
mock_api = mocker.MagicMock()
mock_api.side_effect = [
StringIO(u'{"available_versions":{"v1":"v1/"}}'),
StringIO(u'{"results":[{"id":"123","github_user":"test_owner","github_repo": "test_role"}]}'),
StringIO(u'{"results":[{"name": "0.0.1"},{"name": "0.0.2","download_url":"http://localhost:8080/test_owner/test_role/0.0.2.tar.gz"}]}'),
]
monkeypatch.setattr(api, 'open_url', mock_api)
role.GalaxyRole(Galaxy(), galaxy_server, 'test_owner.test_role', version="0.0.1").install()
assert mock_role_download_api.call_count == 1
assert mock_role_download_api.mock_calls[0][1][0] == 'https://github.com/test_owner/test_role/archive/0.0.1.tar.gz'
def test_role_download_url(init_mock_temp_file, mocker, galaxy_server, mock_role_download_api, monkeypatch):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,175 |
ansible-galaxy role import always exits 0 even if import failed
|
### Summary
When a role import fails, the galaxy cli code does not alter the exit code for the command accordingly. It is always zero.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/galaxy.py#L1818C1-L1833C17
```
if context.CLIARGS['check_status'] or context.CLIARGS['wait']:
# Get the status of the import
msg_list = []
finished = False
while not finished:
task = self.api.get_import_task(task_id=task[0]['id'])
for msg in task[0]['summary_fields']['task_messages']:
if msg['id'] not in msg_list:
display.display(msg['message_text'], color=colors[msg['message_type']])
msg_list.append(msg['id'])
if task[0]['state'] in ['SUCCESS', 'FAILED']:
finished = True
else:
time.sleep(10)
return 0
```
The code knows the task is "finished" if state is either SUCCESS or FAILED, but the FAILED state does not affect the return value.
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
(venv) [jtanner@p1 galaxy_ng.role_exception_logging]$ ansible-galaxy --version
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying
out features under development. This is a rapidly changing source of code and can become unstable at any point.
ansible-galaxy [core 2.17.0.dev0] (devel fd009a073a) last updated 2023/11/08 12:01:58 (GMT -400)
config file = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.cfg
configured module search path = ['/home/jtanner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/lib/ansible
ansible collection location = /home/jtanner/.ansible/collections:/usr/share/ansible/collections
executable location = /home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/ansible.core/bin/ansible-galaxy
python version = 3.11.6 (main, Oct 3 2023, 00:00:00) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] (/home/jtanner/workspace/github/jctanner.redhat/galaxy_ng.role_exception_logging/venv/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
N/A
```
### OS / Environment
Fedora 38
### Steps to Reproduce
1. Setup a galaxy server
2. ansible-galaxy role import -vvvv nephelaiio ansible-role-packetbeat
### Expected Results
The ansible-galaxy command should exit non-zero if the task is in a FAILED state.
### Actual Results
```console
exit 0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82175
|
https://github.com/ansible/ansible/pull/82193
|
7f2ad7eea673233223948e0d2a9fc5ee683040ce
|
fe81164fe548d79fbcd0024836d5f7474403c95d
| 2023-11-08T17:14:35Z |
python
| 2023-12-12T18:59:19Z |
test/units/galaxy/test_role_install.py
|
mock_api = mocker.MagicMock()
mock_api.side_effect = [
StringIO(u'{"available_versions":{"v1":"v1/"}}'),
StringIO(u'{"results":[{"id":"123","github_user":"test_owner","github_repo": "test_role"}]}'),
StringIO(u'{"results":[{"name": "0.0.1","download_url":"http://localhost:8080/test_owner/test_role/0.0.1.tar.gz"},'
u'{"name": "0.0.2","download_url":"http://localhost:8080/test_owner/test_role/0.0.2.tar.gz"}]}'),
]
monkeypatch.setattr(api, 'open_url', mock_api)
role.GalaxyRole(Galaxy(), galaxy_server, 'test_owner.test_role', version="0.0.1").install()
assert mock_role_download_api.call_count == 1
assert mock_role_download_api.mock_calls[0][1][0] == 'http://localhost:8080/test_owner/test_role/0.0.1.tar.gz'
def test_role_download_url_default_version(init_mock_temp_file, mocker, galaxy_server, mock_role_download_api, monkeypatch):
mock_api = mocker.MagicMock()
mock_api.side_effect = [
StringIO(u'{"available_versions":{"v1":"v1/"}}'),
StringIO(u'{"results":[{"id":"123","github_user":"test_owner","github_repo": "test_role"}]}'),
StringIO(u'{"results":[{"name": "0.0.1","download_url":"http://localhost:8080/test_owner/test_role/0.0.1.tar.gz"},'
u'{"name": "0.0.2","download_url":"http://localhost:8080/test_owner/test_role/0.0.2.tar.gz"}]}'),
]
monkeypatch.setattr(api, 'open_url', mock_api)
role.GalaxyRole(Galaxy(), galaxy_server, 'test_owner.test_role').install()
assert mock_role_download_api.call_count == 1
assert mock_role_download_api.mock_calls[0][1][0] == 'http://localhost:8080/test_owner/test_role/0.0.2.tar.gz'
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
#
#
#
#
from __future__ import annotations
import cmd
import functools
import os
import pprint
import queue
import sys
import threading
import time
import typing as t
from collections import deque
from multiprocessing import Lock
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
from jinja2.exceptions import UndefinedError
from ansible import constants as C
from ansible import context
from ansible.errors import AnsibleError, AnsibleFileNotFound, AnsibleUndefinedVariable, AnsibleParserError
from ansible.executor import action_write_locks
from ansible.executor.play_iterator import IteratingStates, PlayIterator
from ansible.executor.process.worker import WorkerProcess
from ansible.executor.task_result import TaskResult
from ansible.executor.task_queue_manager import CallbackSend, DisplaySend, PromptSend
from ansible.module_utils.six import string_types
from ansible.module_utils.common.text.converters import to_text
from ansible.module_utils.connection import Connection, ConnectionError
from ansible.playbook.conditional import Conditional
from ansible.playbook.handler import Handler
from ansible.playbook.helpers import load_list_of_blocks
from ansible.playbook.task import Task
from ansible.playbook.task_include import TaskInclude
from ansible.plugins import loader as plugin_loader
from ansible.template import Templar
from ansible.utils.display import Display
from ansible.utils.fqcn import add_internal_fqcns
from ansible.utils.unsafe_proxy import wrap_var
from ansible.utils.vars import combine_vars, isidentifier
from ansible.vars.clean import strip_internal_keys, module_response_deepcopy
display = Display()
__all__ = ['StrategyBase']
ALWAYS_DELEGATE_FACT_PREFIXES = frozenset((
'discovered_interpreter_',
))
class StrategySentinel:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
pass
_sentinel = StrategySentinel()
def post_process_whens(result, task, templar, task_vars):
cond = None
if task.changed_when:
with templar.set_temporary_context(available_variables=task_vars):
cond = Conditional(loader=templar._loader)
cond.when = task.changed_when
result['changed'] = cond.evaluate_conditional(templar, templar.available_variables)
if task.failed_when:
with templar.set_temporary_context(available_variables=task_vars):
if cond is None:
cond = Conditional(loader=templar._loader)
cond.when = task.failed_when
failed_when_result = cond.evaluate_conditional(templar, templar.available_variables)
result['failed_when_result'] = result['failed'] = failed_when_result
def _get_item_vars(result, task):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
item_vars = {}
if task.loop or task.loop_with:
loop_var = result.get('ansible_loop_var', 'item')
index_var = result.get('ansible_index_var')
if loop_var in result:
item_vars[loop_var] = result[loop_var]
if index_var and index_var in result:
item_vars[index_var] = result[index_var]
if '_ansible_item_label' in result:
item_vars['_ansible_item_label'] = result['_ansible_item_label']
if 'ansible_loop' in result:
item_vars['ansible_loop'] = result['ansible_loop']
return item_vars
def results_thread_main(strategy):
while True:
try:
result = strategy._final_q.get()
if isinstance(result, StrategySentinel):
break
elif isinstance(result, DisplaySend):
dmethod = getattr(display, result.method)
dmethod(*result.args, **result.kwargs)
elif isinstance(result, CallbackSend):
for arg in result.args:
if isinstance(arg, TaskResult):
strategy.normalize_task_result(arg)
break
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
strategy._tqm.send_callback(result.method_name, *result.args, **result.kwargs)
elif isinstance(result, TaskResult):
strategy.normalize_task_result(result)
with strategy._results_lock:
strategy._results.append(result)
elif isinstance(result, PromptSend):
try:
value = display.prompt_until(
result.prompt,
private=result.private,
seconds=result.seconds,
complete_input=result.complete_input,
interrupt_input=result.interrupt_input,
)
except AnsibleError as e:
value = e
except BaseException as e:
try:
raise AnsibleError(f"{e}") from e
except AnsibleError as e:
value = e
strategy._workers[result.worker_id].worker_queue.put(value)
else:
display.warning('Received an invalid object (%s) in the result queue: %r' % (type(result), result))
except (IOError, EOFError):
break
except queue.Empty:
pass
def debug_closure(func):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
"""Closure to wrap ``StrategyBase._process_pending_results`` and invoke the task debugger"""
@functools.wraps(func)
def inner(self, iterator, one_pass=False, max_passes=None):
status_to_stats_map = (
('is_failed', 'failures'),
('is_unreachable', 'dark'),
('is_changed', 'changed'),
('is_skipped', 'skipped'),
)
prev_host_states = iterator.host_states.copy()
results = func(self, iterator, one_pass=one_pass, max_passes=max_passes)
_processed_results = []
for result in results:
task = result._task
host = result._host
_queued_task_args = self._queued_task_cache.pop((host.name, task._uuid), None)
task_vars = _queued_task_args['task_vars']
play_context = _queued_task_args['play_context']
try:
prev_host_state = prev_host_states[host.name]
except KeyError:
prev_host_state = iterator.get_host_state(host)
while result.needs_debugger(globally_enabled=self.debugger_active):
next_action = NextAction()
dbg = Debugger(task, host, task_vars, play_context, result, next_action)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
dbg.cmdloop()
if next_action.result == NextAction.REDO:
self._tqm.clear_failed_hosts()
if task.run_once and iterator._play.strategy in add_internal_fqcns(('linear',)) and result.is_failed():
for host_name, state in prev_host_states.items():
if host_name == host.name:
continue
iterator.set_state_for_host(host_name, state)
iterator._play._removed_hosts.remove(host_name)
iterator.set_state_for_host(host.name, prev_host_state)
for method, what in status_to_stats_map:
if getattr(result, method)():
self._tqm._stats.decrement(what, host.name)
self._tqm._stats.decrement('ok', host.name)
self._queue_task(host, task, task_vars, play_context)
_processed_results.extend(debug_closure(func)(self, iterator, one_pass))
break
elif next_action.result == NextAction.CONTINUE:
_processed_results.append(result)
break
elif next_action.result == NextAction.EXIT:
sys.exit(99)
else:
_processed_results.append(result)
return _processed_results
return inner
class StrategyBase:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
'''
This is the base class for strategy plugins, which contains some common
code useful to all strategies like running handlers, cleanup actions, etc.
'''
ALLOW_BASE_THROTTLING = True
def __init__(self, tqm):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
self._tqm = tqm
self._inventory = tqm.get_inventory()
self._workers = tqm._workers
self._variable_manager = tqm.get_variable_manager()
self._loader = tqm.get_loader()
self._final_q = tqm._final_q
self._step = context.CLIARGS.get('step', False)
self._diff = context.CLIARGS.get('diff', False)
self._queued_task_cache = {}
self._display = display
self._pending_results = 0
self._cur_worker = 0
self._blocked_hosts = dict()
self._results = deque()
self._results_lock = threading.Condition(threading.Lock())
self._worker_queues = dict()
self._results_thread = threading.Thread(target=results_thread_main, args=(self,))
self._results_thread.daemon = True
self._results_thread.start()
self._active_connections = dict()
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
self._hosts_cache = []
self._hosts_cache_all = []
self.debugger_active = C.ENABLE_TASK_DEBUGGER
def _set_hosts_cache(self, play, refresh=True):
"""Responsible for setting _hosts_cache and _hosts_cache_all
See comment in ``__init__`` for the purpose of these caches
"""
if not refresh and all((self._hosts_cache, self._hosts_cache_all)):
return
if not play.finalized and Templar(None).is_template(play.hosts):
_pattern = 'all'
else:
_pattern = play.hosts or 'all'
self._hosts_cache_all = [h.name for h in self._inventory.get_hosts(pattern=_pattern, ignore_restrictions=True)]
self._hosts_cache = [h.name for h in self._inventory.get_hosts(play.hosts, order=play.order)]
def cleanup(self):
for sock in self._active_connections.values():
try:
conn = Connection(sock)
conn.reset()
except ConnectionError as e:
display.debug("got an error while closing persistent connection: %s" % e)
self._final_q.put(_sentinel)
self._results_thread.join()
def run(self, iterator, play_context, result=0):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
for host in self._hosts_cache:
if host not in self._tqm._unreachable_hosts:
try:
iterator.get_next_task_for_host(self._inventory.hosts[host])
except KeyError:
iterator.get_next_task_for_host(self._inventory.get_host(host))
if not isinstance(result, bool) and result != self._tqm.RUN_OK:
return result
elif len(self._tqm._unreachable_hosts.keys()) > 0:
return self._tqm.RUN_UNREACHABLE_HOSTS
elif len(iterator.get_failed_hosts()) > 0:
return self._tqm.RUN_FAILED_HOSTS
else:
return self._tqm.RUN_OK
def get_hosts_remaining(self, play):
self._set_hosts_cache(play, refresh=False)
ignore = set(self._tqm._failed_hosts).union(self._tqm._unreachable_hosts)
return [host for host in self._hosts_cache if host not in ignore]
def get_failed_hosts(self, play):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
self._set_hosts_cache(play, refresh=False)
return [host for host in self._hosts_cache if host in self._tqm._failed_hosts]
def add_tqm_variables(self, vars, play):
'''
Base class method to add extra variables/information to the list of task
vars sent through the executor engine regarding the task queue manager state.
'''
vars['ansible_current_hosts'] = self.get_hosts_remaining(play)
vars['ansible_failed_hosts'] = self.get_failed_hosts(play)
def _queue_task(self, host, task, task_vars, play_context):
''' handles queueing the task up to be sent to a worker '''
display.debug("entering _queue_task() for %s/%s" % (host.name, task.action))
if task.action not in action_write_locks.action_write_locks:
display.debug('Creating lock for %s' % task.action)
action_write_locks.action_write_locks[task.action] = Lock()
templar = Templar(loader=self._loader, variables=task_vars)
try:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
throttle = int(templar.template(task.throttle))
except Exception as e:
raise AnsibleError("Failed to convert the throttle value to an integer.", obj=task._ds, orig_exc=e)
try:
rewind_point = len(self._workers)
if throttle > 0 and self.ALLOW_BASE_THROTTLING:
if task.run_once:
display.debug("Ignoring 'throttle' as 'run_once' is also set for '%s'" % task.get_name())
else:
if throttle <= rewind_point:
display.debug("task: %s, throttle: %d" % (task.get_name(), throttle))
rewind_point = throttle
queued = False
starting_worker = self._cur_worker
while True:
if self._cur_worker >= rewind_point:
self._cur_worker = 0
worker_prc = self._workers[self._cur_worker]
if worker_prc is None or not worker_prc.is_alive():
self._queued_task_cache[(host.name, task._uuid)] = {
'host': host,
'task': task,
'task_vars': task_vars,
'play_context': play_context
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
}
worker_prc = WorkerProcess(
self._final_q, task_vars, host, task, play_context, self._loader, self._variable_manager, plugin_loader, self._cur_worker,
)
self._workers[self._cur_worker] = worker_prc
self._tqm.send_callback('v2_runner_on_start', host, task)
worker_prc.start()
display.debug("worker is %d (out of %d available)" % (self._cur_worker + 1, len(self._workers)))
queued = True
self._cur_worker += 1
if self._cur_worker >= rewind_point:
self._cur_worker = 0
if queued:
break
elif self._cur_worker == starting_worker:
time.sleep(0.0001)
self._pending_results += 1
except (EOFError, IOError, AssertionError) as e:
display.debug("got an error while queuing: %s" % e)
return
display.debug("exiting _queue_task() for %s/%s" % (host.name, task.action))
def get_task_hosts(self, iterator, task_host, task):
if task.run_once:
host_list = [host for host in self._hosts_cache if host not in self._tqm._unreachable_hosts]
else:
host_list = [task_host.name]
return host_list
def get_delegated_hosts(self, result, task):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
host_name = result.get('_ansible_delegated_vars', {}).get('ansible_delegated_host', None)
return [host_name or task.delegate_to]
def _set_always_delegated_facts(self, result, task):
"""Sets host facts for ``delegate_to`` hosts for facts that should
always be delegated
This operation mutates ``result`` to remove the always delegated facts
See ``ALWAYS_DELEGATE_FACT_PREFIXES``
"""
if task.delegate_to is None:
return
facts = result['ansible_facts']
always_keys = set()
_add = always_keys.add
for fact_key in facts:
for always_key in ALWAYS_DELEGATE_FACT_PREFIXES:
if fact_key.startswith(always_key):
_add(fact_key)
if always_keys:
_pop = facts.pop
always_facts = {
'ansible_facts': dict((k, _pop(k)) for k in list(facts) if k in always_keys)
}
host_list = self.get_delegated_hosts(result, task)
_set_host_facts = self._variable_manager.set_host_facts
for target_host in host_list:
_set_host_facts(target_host, always_facts)
def normalize_task_result(self, task_result):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
"""Normalize a TaskResult to reference actual Host and Task objects
when only given the ``Host.name``, or the ``Task._uuid``
Only the ``Host.name`` and ``Task._uuid`` are commonly sent back from
the ``TaskExecutor`` or ``WorkerProcess`` due to performance concerns
Mutates the original object
"""
if isinstance(task_result._host, string_types):
task_result._host = self._inventory.get_host(to_text(task_result._host))
if isinstance(task_result._task, string_types):
queue_cache_entry = (task_result._host.name, task_result._task)
try:
found_task = self._queued_task_cache[queue_cache_entry]['task']
except KeyError:
if task_result._task_fields.get('action') != 'async_status':
raise
original_task = Task()
else:
original_task = found_task.copy(exclude_parent=True, exclude_tasks=True)
original_task._parent = found_task._parent
original_task.from_attrs(task_result._task_fields)
task_result._task = original_task
return task_result
def search_handlers_by_notification(self, notification: str, iterator: PlayIterator) -> t.Generator[Handler, None, None]:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
templar = Templar(None)
handlers = [h for b in reversed(iterator._play.handlers) for h in b.block]
for handler in handlers:
if not handler.name:
continue
if not handler.cached_name:
if templar.is_template(handler.name):
templar.available_variables = self._variable_manager.get_vars(
play=iterator._play,
task=handler,
_hosts=self._hosts_cache,
_hosts_all=self._hosts_cache_all
)
try:
handler.name = templar.template(handler.name)
except (UndefinedError, AnsibleUndefinedVariable) as e:
if not handler.listen:
display.warning(
"Handler '%s' is unusable because it has no listen topics and "
"the name could not be templated (host-specific variables are "
"not supported in handler names). The error: %s" % (handler.name, to_text(e))
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
)
continue
handler.cached_name = True
if notification in {
handler.name,
handler.get_name(include_role_fqcn=False),
handler.get_name(include_role_fqcn=True),
}:
yield handler
break
templar.available_variables = {}
seen = []
for handler in handlers:
if listeners := handler.listen:
if notification in handler.get_validated_value(
'listen',
handler.fattributes.get('listen'),
listeners,
templar,
):
if handler.name and handler.name in seen:
continue
seen.append(handler.name)
yield handler
@debug_closure
def _process_pending_results(self, iterator, one_pass=False, max_passes=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
'''
Reads results off the final queue and takes appropriate action
based on the result (executing callbacks, updating state, etc.).
'''
ret_results = []
cur_pass = 0
while True:
try:
self._results_lock.acquire()
task_result = self._results.popleft()
except IndexError:
break
finally:
self._results_lock.release()
original_host = task_result._host
original_task = task_result._task
role_ran = False
if task_result.is_failed():
role_ran = True
ignore_errors = original_task.ignore_errors
if not ignore_errors:
state_when_failed = iterator.get_state_for_host(original_host.name)
display.debug("marking %s as failed" % original_host.name)
if original_task.run_once:
for h in self._inventory.get_hosts(iterator._play.hosts):
if h.name not in self._tqm._unreachable_hosts:
iterator.mark_host_failed(h)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
else:
iterator.mark_host_failed(original_host)
state, dummy = iterator.get_next_task_for_host(original_host, peek=True)
if iterator.is_failed(original_host) and state and state.run_state == IteratingStates.COMPLETE:
self._tqm._failed_hosts[original_host.name] = True
if iterator.is_any_block_rescuing(state_when_failed):
self._tqm._stats.increment('rescued', original_host.name)
iterator._play._removed_hosts.remove(original_host.name)
self._variable_manager.set_nonpersistent_facts(
original_host.name,
dict(
ansible_failed_task=wrap_var(original_task.serialize()),
ansible_failed_result=task_result._result,
),
)
else:
self._tqm._stats.increment('failures', original_host.name)
else:
self._tqm._stats.increment('ok', original_host.name)
self._tqm._stats.increment('ignored', original_host.name)
if 'changed' in task_result._result and task_result._result['changed']:
self._tqm._stats.increment('changed', original_host.name)
self._tqm.send_callback('v2_runner_on_failed', task_result, ignore_errors=ignore_errors)
elif task_result.is_unreachable():
ignore_unreachable = original_task.ignore_unreachable
if not ignore_unreachable:
self._tqm._unreachable_hosts[original_host.name] = True
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
iterator._play._removed_hosts.append(original_host.name)
self._tqm._stats.increment('dark', original_host.name)
else:
self._tqm._stats.increment('ok', original_host.name)
self._tqm._stats.increment('ignored', original_host.name)
self._tqm.send_callback('v2_runner_on_unreachable', task_result)
elif task_result.is_skipped():
self._tqm._stats.increment('skipped', original_host.name)
self._tqm.send_callback('v2_runner_on_skipped', task_result)
else:
role_ran = True
if original_task.loop:
result_items = task_result._result.get('results', [])
else:
result_items = [task_result._result]
for result_item in result_items:
if '_ansible_notify' in result_item and task_result.is_changed():
host_state = iterator.get_state_for_host(original_host.name)
for notification in result_item['_ansible_notify']:
for handler in self.search_handlers_by_notification(notification, iterator):
if host_state.run_state == IteratingStates.HANDLERS:
if handler.notify_host(original_host):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
self._tqm.send_callback('v2_playbook_on_notify', handler, original_host)
else:
iterator.add_notification(original_host.name, notification)
display.vv(f"Notification for handler {notification} has been saved.")
break
else:
msg = (
f"The requested handler '{notification}' was not found in either the main handlers"
" list nor in the listening handlers list"
)
if C.ERROR_ON_MISSING_HANDLER:
raise AnsibleError(msg)
else:
display.warning(msg)
if 'add_host' in result_item:
new_host_info = result_item.get('add_host', dict())
self._inventory.add_dynamic_host(new_host_info, result_item)
if result_item.get('changed') and new_host_info['host_name'] not in self._hosts_cache_all:
self._hosts_cache_all.append(new_host_info['host_name'])
elif 'add_group' in result_item:
self._inventory.add_dynamic_group(original_host, result_item)
if 'add_host' in result_item or 'add_group' in result_item:
item_vars = _get_item_vars(result_item, original_task)
found_task_vars = self._queued_task_cache.get((original_host.name, task_result._task._uuid))['task_vars']
if item_vars:
all_task_vars = combine_vars(found_task_vars, item_vars)
else:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
all_task_vars = found_task_vars
all_task_vars[original_task.register] = wrap_var(result_item)
post_process_whens(result_item, original_task, Templar(self._loader), all_task_vars)
if original_task.loop or original_task.loop_with:
new_item_result = TaskResult(
task_result._host,
task_result._task,
result_item,
task_result._task_fields,
)
self._tqm.send_callback('v2_runner_item_on_ok', new_item_result)
if result_item.get('changed', False):
task_result._result['changed'] = True
if result_item.get('failed', False):
task_result._result['failed'] = True
if 'ansible_facts' in result_item and original_task.action not in C._ACTION_DEBUG:
if original_task.delegate_to is not None and original_task.delegate_facts:
host_list = self.get_delegated_hosts(result_item, original_task)
else:
self._set_always_delegated_facts(result_item, original_task)
host_list = self.get_task_hosts(iterator, original_host, original_task)
if original_task.action in C._ACTION_INCLUDE_VARS:
for (var_name, var_value) in result_item['ansible_facts'].items():
for target_host in host_list:
self._variable_manager.set_host_variable(target_host, var_name, var_value)
else:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
cacheable = result_item.pop('_ansible_facts_cacheable', False)
for target_host in host_list:
is_set_fact = original_task.action in C._ACTION_SET_FACT
if not is_set_fact or cacheable:
self._variable_manager.set_host_facts(target_host, result_item['ansible_facts'].copy())
if is_set_fact:
self._variable_manager.set_nonpersistent_facts(target_host, result_item['ansible_facts'].copy())
if 'ansible_stats' in result_item and 'data' in result_item['ansible_stats'] and result_item['ansible_stats']['data']:
if 'per_host' not in result_item['ansible_stats'] or result_item['ansible_stats']['per_host']:
host_list = self.get_task_hosts(iterator, original_host, original_task)
else:
host_list = [None]
data = result_item['ansible_stats']['data']
aggregate = 'aggregate' in result_item['ansible_stats'] and result_item['ansible_stats']['aggregate']
for myhost in host_list:
for k in data.keys():
if aggregate:
self._tqm._stats.update_custom_stats(k, data[k], myhost)
else:
self._tqm._stats.set_custom_stats(k, data[k], myhost)
if 'diff' in task_result._result:
if self._diff or getattr(original_task, 'diff', False):
self._tqm.send_callback('v2_on_file_diff', task_result)
if not isinstance(original_task, TaskInclude):
self._tqm._stats.increment('ok', original_host.name)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
if 'changed' in task_result._result and task_result._result['changed']:
self._tqm._stats.increment('changed', original_host.name)
self._tqm.send_callback('v2_runner_on_ok', task_result)
if original_task.register:
if not isidentifier(original_task.register):
raise AnsibleError("Invalid variable name in 'register' specified: '%s'" % original_task.register)
host_list = self.get_task_hosts(iterator, original_host, original_task)
clean_copy = strip_internal_keys(module_response_deepcopy(task_result._result))
if 'invocation' in clean_copy:
del clean_copy['invocation']
for target_host in host_list:
self._variable_manager.set_nonpersistent_facts(target_host, {original_task.register: clean_copy})
self._pending_results -= 1
if original_host.name in self._blocked_hosts:
del self._blocked_hosts[original_host.name]
if original_task._role is not None and role_ran:
role_obj = self._get_cached_role(original_task, iterator._play)
role_obj._had_task_run[original_host.name] = True
ret_results.append(task_result)
if one_pass or max_passes is not None and (cur_pass + 1) >= max_passes:
break
cur_pass += 1
return ret_results
def _wait_on_pending_results(self, iterator):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
'''
Wait for the shared counter to drop to zero, using a short sleep
between checks to ensure we don't spin lock
'''
ret_results = []
display.debug("waiting for pending results...")
while self._pending_results > 0 and not self._tqm._terminated:
if self._tqm.has_dead_workers():
raise AnsibleError("A worker was found in a dead state")
results = self._process_pending_results(iterator)
ret_results.extend(results)
if self._pending_results > 0:
time.sleep(C.DEFAULT_INTERNAL_POLL_INTERVAL)
display.debug("no more pending results, returning what we have")
return ret_results
def _copy_included_file(self, included_file):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
'''
A proven safe and performant way to create a copy of an included file
'''
ti_copy = included_file._task.copy(exclude_parent=True)
ti_copy._parent = included_file._task._parent
temp_vars = ti_copy.vars | included_file._vars
ti_copy.vars = temp_vars
return ti_copy
def _load_included_file(self, included_file, iterator, is_handler=False):
'''
Loads an included YAML file of tasks, applying the optional set of variables.
Raises AnsibleError exception in case of a failure during including a file,
in such case the caller is responsible for marking the host(s) as failed
using PlayIterator.mark_host_failed().
'''
display.debug("loading included file: %s" % included_file._filename)
try:
data = self._loader.load_from_file(included_file._filename)
if data is None:
return []
elif not isinstance(data, list):
raise AnsibleError("included task files must contain a list of tasks")
ti_copy = self._copy_included_file(included_file)
block_list = load_list_of_blocks(
data,
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
play=iterator._play,
parent_block=ti_copy.build_parent_block(),
role=included_file._task._role,
use_handlers=is_handler,
loader=self._loader,
variable_manager=self._variable_manager,
)
for host in included_file._hosts:
self._tqm._stats.increment('ok', host.name)
except AnsibleParserError:
raise
except AnsibleError as e:
if isinstance(e, AnsibleFileNotFound):
reason = "Could not find or access '%s' on the Ansible Controller." % to_text(e.file_name)
else:
reason = to_text(e)
for r in included_file._results:
r._result['failed'] = True
for host in included_file._hosts:
tr = TaskResult(host=host, task=included_file._task, return_data=dict(failed=True, reason=reason))
self._tqm._stats.increment('failures', host.name)
self._tqm.send_callback('v2_runner_on_failed', tr)
raise AnsibleError(reason) from e
self._tqm.send_callback('v2_playbook_on_include', included_file)
display.debug("done processing included file")
return block_list
def _take_step(self, task, host=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
ret = False
msg = u'Perform task: %s ' % task
if host:
msg += u'on %s ' % host
msg += u'(N)o/(y)es/(c)ontinue: '
resp = display.prompt(msg)
if resp.lower() in ['y', 'yes']:
display.debug("User ran task")
ret = True
elif resp.lower() in ['c', 'continue']:
display.debug("User ran task and canceled step mode")
self._step = False
ret = True
else:
display.debug("User skipped task")
display.banner(msg)
return ret
def _cond_not_supported_warn(self, task_name):
display.warning("%s task does not support when conditional" % task_name)
def _execute_meta(self, task, play_context, iterator, target_host):
meta_action = task.args.get('_raw_params')
def _evaluate_conditional(h):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
all_vars = self._variable_manager.get_vars(play=iterator._play, host=h, task=task,
_hosts=self._hosts_cache, _hosts_all=self._hosts_cache_all)
templar = Templar(loader=self._loader, variables=all_vars)
return task.evaluate_conditional(templar, all_vars)
skipped = False
msg = meta_action
skip_reason = '%s conditional evaluated to False' % meta_action
if isinstance(task, Handler):
self._tqm.send_callback('v2_playbook_on_handler_task_start', task)
else:
self._tqm.send_callback('v2_playbook_on_task_start', task, is_conditional=False)
if meta_action in ('noop', 'refresh_inventory', 'reset_connection') and task.when:
self._cond_not_supported_warn(meta_action)
if meta_action == 'noop':
msg = "noop"
elif meta_action == 'flush_handlers':
if _evaluate_conditional(target_host):
host_state = iterator.get_state_for_host(target_host.name)
for notification in list(host_state.handler_notifications):
for handler in self.search_handlers_by_notification(notification, iterator):
if handler.notify_host(target_host):
self._tqm.send_callback('v2_playbook_on_notify', handler, target_host)
iterator.clear_notification(target_host.name, notification)
if host_state.run_state == IteratingStates.HANDLERS:
raise AnsibleError('flush_handlers cannot be used as a handler')
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
if target_host.name not in self._tqm._unreachable_hosts:
host_state.pre_flushing_run_state = host_state.run_state
host_state.run_state = IteratingStates.HANDLERS
msg = "triggered running handlers for %s" % target_host.name
else:
skipped = True
skip_reason += ', not running handlers for %s' % target_host.name
elif meta_action == 'refresh_inventory':
self._inventory.refresh_inventory()
self._set_hosts_cache(iterator._play)
msg = "inventory successfully refreshed"
elif meta_action == 'clear_facts':
if _evaluate_conditional(target_host):
for host in self._inventory.get_hosts(iterator._play.hosts):
hostname = host.get_name()
self._variable_manager.clear_facts(hostname)
msg = "facts cleared"
else:
skipped = True
skip_reason += ', not clearing facts and fact cache for %s' % target_host.name
elif meta_action == 'clear_host_errors':
if _evaluate_conditional(target_host):
for host in self._inventory.get_hosts(iterator._play.hosts):
self._tqm._failed_hosts.pop(host.name, False)
self._tqm._unreachable_hosts.pop(host.name, False)
iterator.clear_host_errors(host)
msg = "cleared host errors"
else:
skipped = True
skip_reason += ', not clearing host error state for %s' % target_host.name
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
elif meta_action == 'end_batch':
if _evaluate_conditional(target_host):
for host in self._inventory.get_hosts(iterator._play.hosts):
if host.name not in self._tqm._unreachable_hosts:
iterator.set_run_state_for_host(host.name, IteratingStates.COMPLETE)
msg = "ending batch"
else:
skipped = True
skip_reason += ', continuing current batch'
elif meta_action == 'end_play':
if _evaluate_conditional(target_host):
for host in self._inventory.get_hosts(iterator._play.hosts):
if host.name not in self._tqm._unreachable_hosts:
iterator.set_run_state_for_host(host.name, IteratingStates.COMPLETE)
iterator.end_play = True
msg = "ending play"
else:
skipped = True
skip_reason += ', continuing play'
elif meta_action == 'end_host':
if _evaluate_conditional(target_host):
iterator.set_run_state_for_host(target_host.name, IteratingStates.COMPLETE)
iterator._play._removed_hosts.append(target_host.name)
msg = "ending play for %s" % target_host.name
else:
skipped = True
skip_reason += ", continuing execution for %s" % target_host.name
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
msg = "end_host conditional evaluated to false, continuing execution for %s" % target_host.name
elif meta_action == 'role_complete':
if task.implicit:
role_obj = self._get_cached_role(task, iterator._play)
if target_host.name in role_obj._had_task_run:
role_obj._completed[target_host.name] = True
msg = 'role_complete for %s' % target_host.name
elif meta_action == 'reset_connection':
all_vars = self._variable_manager.get_vars(play=iterator._play, host=target_host, task=task,
_hosts=self._hosts_cache, _hosts_all=self._hosts_cache_all)
templar = Templar(loader=self._loader, variables=all_vars)
play_context = play_context.set_task_and_variable_override(task=task, variables=all_vars, templar=templar)
play_context.post_validate(templar=templar)
if not play_context.remote_addr:
play_context.remote_addr = target_host.address
play_context.update_vars(all_vars)
if target_host in self._active_connections:
connection = Connection(self._active_connections[target_host])
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
del self._active_connections[target_host]
else:
connection = plugin_loader.connection_loader.get(play_context.connection, play_context, os.devnull)
connection.set_options(task_keys=task.dump_attrs(), var_options=all_vars)
play_context.set_attributes_from_plugin(connection)
if connection:
try:
connection.reset()
msg = 'reset connection'
except ConnectionError as e:
display.debug("got an error while closing persistent connection: %s" % e)
else:
msg = 'no connection, nothing to reset'
else:
raise AnsibleError("invalid meta action requested: %s" % meta_action, obj=task._ds)
result = {'msg': msg}
if skipped:
result['skipped'] = True
result['skip_reason'] = skip_reason
else:
result['changed'] = False
if not task.implicit:
header = skip_reason if skipped else msg
display.vv(f"META: {header}")
res = TaskResult(target_host, task, result)
if skipped:
self._tqm.send_callback('v2_runner_on_skipped', res)
return [res]
def _get_cached_role(self, task, play):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
role_path = task._role.get_role_path()
role_cache = play.role_cache[role_path]
try:
idx = role_cache.index(task._role)
return role_cache[idx]
except ValueError:
raise AnsibleError(f'Cannot locate {task._role.get_name()} in role cache')
def get_hosts_left(self, iterator):
''' returns list of available hosts for this iterator by filtering out unreachables '''
hosts_left = []
for host in self._hosts_cache:
if host not in self._tqm._unreachable_hosts:
try:
hosts_left.append(self._inventory.hosts[host])
except KeyError:
hosts_left.append(self._inventory.get_host(host))
return hosts_left
def update_active_connections(self, results):
''' updates the current active persistent connections '''
for r in results:
if 'args' in r._task_fields:
socket_path = r._task_fields['args'].get('_ansible_socket')
if socket_path:
if r._host not in self._active_connections:
self._active_connections[r._host] = socket_path
class NextAction(object):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
""" The next action after an interpreter's exit. """
REDO = 1
CONTINUE = 2
EXIT = 3
def __init__(self, result=EXIT):
self.result = result
class Debugger(cmd.Cmd):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
prompt_continuous = '> '
def __init__(self, task, host, task_vars, play_context, result, next_action):
cmd.Cmd.__init__(self)
self.prompt = '[%s] %s (debug)> ' % (host, task)
self.intro = None
self.scope = {}
self.scope['task'] = task
self.scope['task_vars'] = task_vars
self.scope['host'] = host
self.scope['play_context'] = play_context
self.scope['result'] = result
self.next_action = next_action
def cmdloop(self):
try:
cmd.Cmd.cmdloop(self)
except KeyboardInterrupt:
pass
do_h = cmd.Cmd.do_help
def do_EOF(self, args):
"""Quit"""
return self.do_quit(args)
def do_quit(self, args):
"""Quit"""
display.display('User interrupted execution')
self.next_action.result = NextAction.EXIT
return True
do_q = do_quit
def do_continue(self, args):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
"""Continue to next result"""
self.next_action.result = NextAction.CONTINUE
return True
do_c = do_continue
def do_redo(self, args):
"""Schedule task for re-execution. The re-execution may not be the next result"""
self.next_action.result = NextAction.REDO
return True
do_r = do_redo
def do_update_task(self, args):
"""Recreate the task from ``task._ds``, and template with updated ``task_vars``"""
templar = Templar(None, variables=self.scope['task_vars'])
task = self.scope['task']
task = task.load_data(task._ds)
task.post_validate(templar)
self.scope['task'] = task
do_u = do_update_task
def evaluate(self, args):
try:
return eval(args, globals(), self.scope)
except Exception:
t, v = sys.exc_info()[:2]
if isinstance(t, str):
exc_type_name = t
else:
exc_type_name = t.__name__
display.display('***%s:%s' % (exc_type_name, repr(v)))
raise
def do_pprint(self, args):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,363 |
Only one handler of a `listen` group is run when notified from another handler
|
### Summary
Hello!
Since ansible-core 2.15 and later (I think since the changes introduced by #79558), it seems that, when multiple handlers of a same `listen` group are notified by another handler, only the first one in the group will be run.
From what I understand, when Ansible handles a `notify` when it is already iterating handlers, it will only consider the first handler that matches the notification, but will not iterate through all the matching handlers. I believe the `break` in `lib/ansible/plugins/strategy/__init__.py` (line 669) should only apply when when Ansible is not already iterating handlers (i.e., in the `else` branch):
https://github.com/ansible/ansible/blob/6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0/lib/ansible/plugins/strategy/__init__.py#L659-L669
I think there seems to be a simple fix to that, which I'm planning to submit as a PR.
Thank you! :)
snip
### Issue Type
Bug Report
### Component Name
handlers
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = None
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.6 (main, Nov 14 2023, 09:36:21) [GCC 13.2.1 20230801] (/usr/bin/python)
jinja version = 3.1.2
libyaml = True
```
### Configuration
```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = /usr/bin/vim
```
### OS / Environment
Arch Linux, with the following Ansible-related packages :
- ansible 9.0.1-1
- ansible-core 2.16.0-1
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
---
- name: test listen-based handlers with recursive notifications
hosts: localhost
gather_facts: false
tasks:
- name: notify handler 1
command: echo
changed_when: true
notify: handler 1
handlers:
- name: handler 1
debug:
msg: handler 1
changed_when: true
notify: handler_2
- name: handler 2a
debug:
msg: handler 2a
listen: handler_2
- name: handler 2b
debug:
msg: handler 2b
listen: handler_2
```
### Expected Results
All handlers should be run, especially both handlers listening on the `handler_2` notification (i.e., `handler 2a` and `handler 2b`):
```
PLAY [test listen-based handlers with recursive notifications] **************************************************************************************
TASK [notify handler 1] *****************************************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.004205", "end": "2023-12-06 10:57:16.556224", "msg": "", "rc": 0, "start": "2023-12-06 10:57:16.552019", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] *************************************************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
NOTIFIED HANDLER handler 2b for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
RUNNING HANDLER [handler 2b] ************************************************************************************************************************
task path: /tmp/ansible/test.yml:24
ok: [localhost] => {
"msg": "handler 2b"
}
PLAY RECAP ******************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Actual Results
```console
PLAY [test listen-based handlers with recursive notifications] ***********************************************************
TASK [notify handler 1] **************************************************************************************************
task path: /tmp/ansible/test.yml:7
Notification for handler handler 1 has been saved.
changed: [localhost] => {"changed": true, "cmd": ["echo"], "delta": "0:00:00.003800", "end": "2023-12-06 10:56:26.513556", "msg": "", "rc": 0, "start": "2023-12-06 10:56:26.509756", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NOTIFIED HANDLER handler 1 for localhost
RUNNING HANDLER [handler 1] **********************************************************************************************
task path: /tmp/ansible/test.yml:13
NOTIFIED HANDLER handler 2a for localhost
changed: [localhost] => {
"msg": "handler 1"
}
RUNNING HANDLER [handler 2a] *********************************************************************************************
task path: /tmp/ansible/test.yml:19
ok: [localhost] => {
"msg": "handler 2a"
}
PLAY RECAP ***************************************************************************************************************
localhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82363
|
https://github.com/ansible/ansible/pull/82364
|
fe81164fe548d79fbcd0024836d5f7474403c95d
|
83281531216ee64cd054959f2bfe54c6df498443
| 2023-12-06T10:05:01Z |
python
| 2023-12-13T09:56:52Z |
lib/ansible/plugins/strategy/__init__.py
|
"""Pretty Print"""
try:
result = self.evaluate(args)
display.display(pprint.pformat(result))
except Exception:
pass
do_p = do_pprint
def execute(self, args):
try:
code = compile(args + '\n', '<stdin>', 'single')
exec(code, globals(), self.scope)
except Exception:
t, v = sys.exc_info()[:2]
if isinstance(t, str):
exc_type_name = t
else:
exc_type_name = t.__name__
display.display('***%s:%s' % (exc_type_name, repr(v)))
raise
def default(self, line):
try:
self.execute(line)
except Exception:
pass
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,353 |
ansible-test sanity should allow multiple documents in EXAMPLES
|
### Summary
EXAMPLES are intended to be copy-and-paste ready.
While most of the documentation is expected to be a single document, it's reasonable to expect that within examples (especially for inventory plugins), there may be multiple documents in there. If only a single document is permitted, then when multiple examples are added for an inventory plugin, attempting to lint the YAML results in key-duplicates errors.
See also https://github.com/ansible/ansible-lint/issues/3860
### Issue Type
Feature Idea
### Component Name
ansible-test
### Additional Information
```yaml (paste below)
EXAMPLES = r"""
---
# Example using groups to assign the running hosts to a group based on vpc_id
plugin: amazon.aws.aws_ec2
profile: aws_profile
# Populate inventory with instances in these regions
regions:
- us-east-2
filters:
# All instances with their state as `running`
instance-state-name: running
keyed_groups:
- prefix: tag
key: tags
compose:
ansible_host: public_dns_name
groups:
libvpc: vpc_id == 'vpc-####'
---
# Define prefix and suffix for host variables coming from AWS.
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
hostvars_prefix: 'aws_'
hostvars_suffix: '_ec2'
"""
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82353
|
https://github.com/ansible/ansible/pull/82355
|
83281531216ee64cd054959f2bfe54c6df498443
|
5346009d2cfab0dcbde675b875a06d2d86b962c5
| 2023-12-05T06:12:52Z |
python
| 2023-12-13T20:18:35Z |
test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py
|
"""Wrapper around yamllint that supports YAML embedded in Ansible modules."""
from __future__ import annotations
import ast
import json
import os
import re
import sys
import typing as t
import yaml
from yaml.resolver import Resolver
from yaml.constructor import SafeConstructor
from yaml.error import MarkedYAMLError
from yaml.cyaml import CParser
from yamllint import linter
from yamllint.config import YamlLintConfig
def main():
"""Main program body."""
paths = sys.argv[1:] or sys.stdin.read().splitlines()
checker = YamlChecker()
checker.check(paths)
checker.report()
class TestConstructor(SafeConstructor):
"""Yaml Safe Constructor that knows about Ansible tags."""
def construct_yaml_unsafe(self, node):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,353 |
ansible-test sanity should allow multiple documents in EXAMPLES
|
### Summary
EXAMPLES are intended to be copy-and-paste ready.
While most of the documentation is expected to be a single document, it's reasonable to expect that within examples (especially for inventory plugins), there may be multiple documents in there. If only a single document is permitted, then when multiple examples are added for an inventory plugin, attempting to lint the YAML results in key-duplicates errors.
See also https://github.com/ansible/ansible-lint/issues/3860
### Issue Type
Feature Idea
### Component Name
ansible-test
### Additional Information
```yaml (paste below)
EXAMPLES = r"""
---
# Example using groups to assign the running hosts to a group based on vpc_id
plugin: amazon.aws.aws_ec2
profile: aws_profile
# Populate inventory with instances in these regions
regions:
- us-east-2
filters:
# All instances with their state as `running`
instance-state-name: running
keyed_groups:
- prefix: tag
key: tags
compose:
ansible_host: public_dns_name
groups:
libvpc: vpc_id == 'vpc-####'
---
# Define prefix and suffix for host variables coming from AWS.
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
hostvars_prefix: 'aws_'
hostvars_suffix: '_ec2'
"""
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82353
|
https://github.com/ansible/ansible/pull/82355
|
83281531216ee64cd054959f2bfe54c6df498443
|
5346009d2cfab0dcbde675b875a06d2d86b962c5
| 2023-12-05T06:12:52Z |
python
| 2023-12-13T20:18:35Z |
test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py
|
"""Construct an unsafe tag."""
try:
constructor = getattr(node, 'id', 'object')
if constructor is not None:
constructor = getattr(self, 'construct_%s' % constructor)
except AttributeError:
constructor = self.construct_object
value = constructor(node)
return value
TestConstructor.add_constructor(
'!unsafe',
TestConstructor.construct_yaml_unsafe)
TestConstructor.add_constructor(
'!vault',
TestConstructor.construct_yaml_str)
TestConstructor.add_constructor(
'!vault-encrypted',
TestConstructor.construct_yaml_str)
class TestLoader(CParser, TestConstructor, Resolver):
"""Custom YAML loader that recognizes custom Ansible tags."""
def __init__(self, stream):
CParser.__init__(self, stream)
TestConstructor.__init__(self)
Resolver.__init__(self)
class YamlChecker:
"""Wrapper around yamllint that supports YAML embedded in Ansible modules."""
def __init__(self):
self.messages = []
def report(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,353 |
ansible-test sanity should allow multiple documents in EXAMPLES
|
### Summary
EXAMPLES are intended to be copy-and-paste ready.
While most of the documentation is expected to be a single document, it's reasonable to expect that within examples (especially for inventory plugins), there may be multiple documents in there. If only a single document is permitted, then when multiple examples are added for an inventory plugin, attempting to lint the YAML results in key-duplicates errors.
See also https://github.com/ansible/ansible-lint/issues/3860
### Issue Type
Feature Idea
### Component Name
ansible-test
### Additional Information
```yaml (paste below)
EXAMPLES = r"""
---
# Example using groups to assign the running hosts to a group based on vpc_id
plugin: amazon.aws.aws_ec2
profile: aws_profile
# Populate inventory with instances in these regions
regions:
- us-east-2
filters:
# All instances with their state as `running`
instance-state-name: running
keyed_groups:
- prefix: tag
key: tags
compose:
ansible_host: public_dns_name
groups:
libvpc: vpc_id == 'vpc-####'
---
# Define prefix and suffix for host variables coming from AWS.
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
hostvars_prefix: 'aws_'
hostvars_suffix: '_ec2'
"""
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82353
|
https://github.com/ansible/ansible/pull/82355
|
83281531216ee64cd054959f2bfe54c6df498443
|
5346009d2cfab0dcbde675b875a06d2d86b962c5
| 2023-12-05T06:12:52Z |
python
| 2023-12-13T20:18:35Z |
test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py
|
"""Print yamllint report to stdout."""
report = dict(
messages=self.messages,
)
print(json.dumps(report, indent=4, sort_keys=True))
def check(self, paths):
"""Check the specified paths."""
config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config')
yaml_conf = YamlLintConfig(file=os.path.join(config_path, 'default.yml'))
module_conf = YamlLintConfig(file=os.path.join(config_path, 'modules.yml'))
plugin_conf = YamlLintConfig(file=os.path.join(config_path, 'plugins.yml'))
for path in paths:
extension = os.path.splitext(path)[1]
with open(path, encoding='utf-8') as file:
contents = file.read()
if extension in ('.yml', '.yaml'):
self.check_yaml(yaml_conf, path, contents)
elif extension == '.py':
if path.startswith('lib/ansible/modules/') or path.startswith('plugins/modules/'):
conf = module_conf
else:
conf = plugin_conf
self.check_module(conf, path, contents)
else:
raise Exception('unsupported extension: %s' % extension)
def check_yaml(self, conf, path, contents):
"""Check the given YAML."""
self.check_parsable(path, contents)
self.messages += [self.result_to_message(r, path) for r in linter.run(contents, conf, path)]
def check_module(self, conf, path, contents):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,353 |
ansible-test sanity should allow multiple documents in EXAMPLES
|
### Summary
EXAMPLES are intended to be copy-and-paste ready.
While most of the documentation is expected to be a single document, it's reasonable to expect that within examples (especially for inventory plugins), there may be multiple documents in there. If only a single document is permitted, then when multiple examples are added for an inventory plugin, attempting to lint the YAML results in key-duplicates errors.
See also https://github.com/ansible/ansible-lint/issues/3860
### Issue Type
Feature Idea
### Component Name
ansible-test
### Additional Information
```yaml (paste below)
EXAMPLES = r"""
---
# Example using groups to assign the running hosts to a group based on vpc_id
plugin: amazon.aws.aws_ec2
profile: aws_profile
# Populate inventory with instances in these regions
regions:
- us-east-2
filters:
# All instances with their state as `running`
instance-state-name: running
keyed_groups:
- prefix: tag
key: tags
compose:
ansible_host: public_dns_name
groups:
libvpc: vpc_id == 'vpc-####'
---
# Define prefix and suffix for host variables coming from AWS.
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
hostvars_prefix: 'aws_'
hostvars_suffix: '_ec2'
"""
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82353
|
https://github.com/ansible/ansible/pull/82355
|
83281531216ee64cd054959f2bfe54c6df498443
|
5346009d2cfab0dcbde675b875a06d2d86b962c5
| 2023-12-05T06:12:52Z |
python
| 2023-12-13T20:18:35Z |
test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py
|
"""Check the given module."""
docs = self.get_module_docs(path, contents)
for key, value in docs.items():
yaml_data = value['yaml']
lineno = value['lineno']
fmt = value['fmt']
if fmt != 'yaml':
continue
if yaml_data.startswith('\n'):
yaml_data = yaml_data[1:]
lineno += 1
self.check_parsable(path, yaml_data, lineno)
messages = list(linter.run(yaml_data, conf, path))
self.messages += [self.result_to_message(r, path, lineno - 1, key) for r in messages]
def check_parsable(self, path, contents, lineno=1):
"""Check the given contents to verify they can be parsed as YAML."""
try:
yaml.load(contents, Loader=TestLoader)
except MarkedYAMLError as ex:
self.messages += [{'code': 'unparsable-with-libyaml',
'message': '%s - %s' % (ex.args[0], ex.args[2]),
'path': path,
'line': ex.problem_mark.line + lineno,
'column': ex.problem_mark.column + 1,
'level': 'error',
}]
@staticmethod
def result_to_message(result, path, line_offset=0, prefix=''):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,353 |
ansible-test sanity should allow multiple documents in EXAMPLES
|
### Summary
EXAMPLES are intended to be copy-and-paste ready.
While most of the documentation is expected to be a single document, it's reasonable to expect that within examples (especially for inventory plugins), there may be multiple documents in there. If only a single document is permitted, then when multiple examples are added for an inventory plugin, attempting to lint the YAML results in key-duplicates errors.
See also https://github.com/ansible/ansible-lint/issues/3860
### Issue Type
Feature Idea
### Component Name
ansible-test
### Additional Information
```yaml (paste below)
EXAMPLES = r"""
---
# Example using groups to assign the running hosts to a group based on vpc_id
plugin: amazon.aws.aws_ec2
profile: aws_profile
# Populate inventory with instances in these regions
regions:
- us-east-2
filters:
# All instances with their state as `running`
instance-state-name: running
keyed_groups:
- prefix: tag
key: tags
compose:
ansible_host: public_dns_name
groups:
libvpc: vpc_id == 'vpc-####'
---
# Define prefix and suffix for host variables coming from AWS.
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
hostvars_prefix: 'aws_'
hostvars_suffix: '_ec2'
"""
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82353
|
https://github.com/ansible/ansible/pull/82355
|
83281531216ee64cd054959f2bfe54c6df498443
|
5346009d2cfab0dcbde675b875a06d2d86b962c5
| 2023-12-05T06:12:52Z |
python
| 2023-12-13T20:18:35Z |
test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py
|
"""Convert the given result to a dictionary and return it."""
if prefix:
prefix = '%s: ' % prefix
return dict(
code=result.rule or result.level,
message=prefix + result.desc,
path=path,
line=result.line + line_offset,
column=result.column,
level=result.level,
)
def get_module_docs(self, path, contents):
"""Return the module documentation for the given module contents."""
module_doc_types = [
'DOCUMENTATION',
'EXAMPLES',
'RETURN',
]
docs = {}
fmt_re = re.compile(r'^# fmt:\s+(\S+)')
def check_assignment(statement, doc_types=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,353 |
ansible-test sanity should allow multiple documents in EXAMPLES
|
### Summary
EXAMPLES are intended to be copy-and-paste ready.
While most of the documentation is expected to be a single document, it's reasonable to expect that within examples (especially for inventory plugins), there may be multiple documents in there. If only a single document is permitted, then when multiple examples are added for an inventory plugin, attempting to lint the YAML results in key-duplicates errors.
See also https://github.com/ansible/ansible-lint/issues/3860
### Issue Type
Feature Idea
### Component Name
ansible-test
### Additional Information
```yaml (paste below)
EXAMPLES = r"""
---
# Example using groups to assign the running hosts to a group based on vpc_id
plugin: amazon.aws.aws_ec2
profile: aws_profile
# Populate inventory with instances in these regions
regions:
- us-east-2
filters:
# All instances with their state as `running`
instance-state-name: running
keyed_groups:
- prefix: tag
key: tags
compose:
ansible_host: public_dns_name
groups:
libvpc: vpc_id == 'vpc-####'
---
# Define prefix and suffix for host variables coming from AWS.
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
hostvars_prefix: 'aws_'
hostvars_suffix: '_ec2'
"""
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82353
|
https://github.com/ansible/ansible/pull/82355
|
83281531216ee64cd054959f2bfe54c6df498443
|
5346009d2cfab0dcbde675b875a06d2d86b962c5
| 2023-12-05T06:12:52Z |
python
| 2023-12-13T20:18:35Z |
test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py
|
"""Check the given statement for a documentation assignment."""
for target in statement.targets:
if not isinstance(target, ast.Name):
continue
if doc_types and target.id not in doc_types:
continue
fmt_match = fmt_re.match(statement.value.value.lstrip())
fmt = 'yaml'
if fmt_match:
fmt = fmt_match.group(1)
docs[target.id] = dict(
yaml=statement.value.value,
lineno=statement.lineno,
end_lineno=statement.lineno + len(statement.value.value.splitlines()),
fmt=fmt.lower(),
)
module_ast = self.parse_module(path, contents)
if not module_ast:
return {}
is_plugin = path.startswith('lib/ansible/modules/') or path.startswith('lib/ansible/plugins/') or path.startswith('plugins/')
is_doc_fragment = path.startswith('lib/ansible/plugins/doc_fragments/') or path.startswith('plugins/doc_fragments/')
if is_plugin and not is_doc_fragment:
for body_statement in module_ast.body:
if isinstance(body_statement, ast.Assign):
check_assignment(body_statement, module_doc_types)
elif is_doc_fragment:
for body_statement in module_ast.body:
if isinstance(body_statement, ast.ClassDef):
for class_statement in body_statement.body:
if isinstance(class_statement, ast.Assign):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,353 |
ansible-test sanity should allow multiple documents in EXAMPLES
|
### Summary
EXAMPLES are intended to be copy-and-paste ready.
While most of the documentation is expected to be a single document, it's reasonable to expect that within examples (especially for inventory plugins), there may be multiple documents in there. If only a single document is permitted, then when multiple examples are added for an inventory plugin, attempting to lint the YAML results in key-duplicates errors.
See also https://github.com/ansible/ansible-lint/issues/3860
### Issue Type
Feature Idea
### Component Name
ansible-test
### Additional Information
```yaml (paste below)
EXAMPLES = r"""
---
# Example using groups to assign the running hosts to a group based on vpc_id
plugin: amazon.aws.aws_ec2
profile: aws_profile
# Populate inventory with instances in these regions
regions:
- us-east-2
filters:
# All instances with their state as `running`
instance-state-name: running
keyed_groups:
- prefix: tag
key: tags
compose:
ansible_host: public_dns_name
groups:
libvpc: vpc_id == 'vpc-####'
---
# Define prefix and suffix for host variables coming from AWS.
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
hostvars_prefix: 'aws_'
hostvars_suffix: '_ec2'
"""
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/82353
|
https://github.com/ansible/ansible/pull/82355
|
83281531216ee64cd054959f2bfe54c6df498443
|
5346009d2cfab0dcbde675b875a06d2d86b962c5
| 2023-12-05T06:12:52Z |
python
| 2023-12-13T20:18:35Z |
test/lib/ansible_test/_util/controller/sanity/yamllint/yamllinter.py
|
check_assignment(class_statement)
else:
raise Exception('unsupported path: %s' % path)
return docs
def parse_module(self, path, contents):
"""Parse the given contents and return a module if successful, otherwise return None."""
try:
return ast.parse(contents)
except SyntaxError as ex:
self.messages.append(dict(
code='python-syntax-error',
message=str(ex),
path=path,
line=ex.lineno,
column=ex.offset,
level='error',
))
except Exception as ex:
self.messages.append(dict(
code='python-parse-error',
message=str(ex),
path=path,
line=0,
column=0,
level='error',
))
return None
if __name__ == '__main__':
main()
|
closed
|
dagger/dagger
|
https://github.com/dagger/dagger
| 276 |
Multiple deployments with the same name?
|
It appears multiple deployments can have the same name, which is confusing.
```
$ dagger up
7:50PM FTL system | multiple deployments match the current directory, select one with `--deployment` deploymentPath=/home/shykes/dagger deployments=[
"dagger",
"dagger-dev",
"dagger-dev"
]
```
```
$ ls ~/.dagger/store/
dagger dagger-dev react
```
|
https://github.com/dagger/dagger/issues/276
|
https://github.com/dagger/dagger/pull/279
|
1ae0ce65e90e4ff3b67317c957636b64058e1f35
|
7cf1163a2b7055a1dae6cdf36aad295398e2487a
| 2021-04-05T19:52:47Z |
go
| 2021-04-06T00:09:35Z |
dagger/store.go
|
package dagger
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path"
"sync"
"github.com/google/uuid"
)
var (
ErrDeploymentExist = errors.New("deployment already exists")
ErrDeploymentNotExist = errors.New("deployment doesn't exist")
)
const (
defaultStoreRoot = "$HOME/.dagger/store"
)
type Store struct {
root string
l sync.RWMutex
deployments map[string]*DeploymentState
deploymentsByName map[string]*DeploymentState
deploymentsByPath map[string][]*DeploymentState
pathsByDeploymentID map[string][]string
}
func NewStore(root string) (*Store, error) {
|
closed
|
dagger/dagger
|
https://github.com/dagger/dagger
| 276 |
Multiple deployments with the same name?
|
It appears multiple deployments can have the same name, which is confusing.
```
$ dagger up
7:50PM FTL system | multiple deployments match the current directory, select one with `--deployment` deploymentPath=/home/shykes/dagger deployments=[
"dagger",
"dagger-dev",
"dagger-dev"
]
```
```
$ ls ~/.dagger/store/
dagger dagger-dev react
```
|
https://github.com/dagger/dagger/issues/276
|
https://github.com/dagger/dagger/pull/279
|
1ae0ce65e90e4ff3b67317c957636b64058e1f35
|
7cf1163a2b7055a1dae6cdf36aad295398e2487a
| 2021-04-05T19:52:47Z |
go
| 2021-04-06T00:09:35Z |
dagger/store.go
|
store := &Store{
root: root,
deployments: make(map[string]*DeploymentState),
deploymentsByName: make(map[string]*DeploymentState),
deploymentsByPath: make(map[string][]*DeploymentState),
pathsByDeploymentID: make(map[string][]string),
}
return store, store.loadAll()
}
func DefaultStore() (*Store, error) {
if root := os.Getenv("DAGGER_STORE"); root != "" {
return NewStore(root)
}
return NewStore(os.ExpandEnv(defaultStoreRoot))
}
func (s *Store) deploymentPath(name string) string {
return path.Join(s.root, name, "deployment.json")
}
func (s *Store) loadAll() error {
files, err := os.ReadDir(s.root)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
|
closed
|
dagger/dagger
|
https://github.com/dagger/dagger
| 276 |
Multiple deployments with the same name?
|
It appears multiple deployments can have the same name, which is confusing.
```
$ dagger up
7:50PM FTL system | multiple deployments match the current directory, select one with `--deployment` deploymentPath=/home/shykes/dagger deployments=[
"dagger",
"dagger-dev",
"dagger-dev"
]
```
```
$ ls ~/.dagger/store/
dagger dagger-dev react
```
|
https://github.com/dagger/dagger/issues/276
|
https://github.com/dagger/dagger/pull/279
|
1ae0ce65e90e4ff3b67317c957636b64058e1f35
|
7cf1163a2b7055a1dae6cdf36aad295398e2487a
| 2021-04-05T19:52:47Z |
go
| 2021-04-06T00:09:35Z |
dagger/store.go
|
return nil
}
return err
}
for _, f := range files {
if !f.IsDir() {
continue
}
if err := s.loadDeployment(f.Name()); err != nil {
return err
}
}
return nil
}
func (s *Store) loadDeployment(name string) error {
data, err := os.ReadFile(s.deploymentPath(name))
if err != nil {
return err
}
var st DeploymentState
if err := json.Unmarshal(data, &st); err != nil {
return err
}
s.indexDeployment(&st)
return nil
}
func (s *Store) syncDeployment(r *DeploymentState) error {
p := s.deploymentPath(r.Name)
if err := os.MkdirAll(path.Dir(p), 0755); err != nil {
return err
|
closed
|
dagger/dagger
|
https://github.com/dagger/dagger
| 276 |
Multiple deployments with the same name?
|
It appears multiple deployments can have the same name, which is confusing.
```
$ dagger up
7:50PM FTL system | multiple deployments match the current directory, select one with `--deployment` deploymentPath=/home/shykes/dagger deployments=[
"dagger",
"dagger-dev",
"dagger-dev"
]
```
```
$ ls ~/.dagger/store/
dagger dagger-dev react
```
|
https://github.com/dagger/dagger/issues/276
|
https://github.com/dagger/dagger/pull/279
|
1ae0ce65e90e4ff3b67317c957636b64058e1f35
|
7cf1163a2b7055a1dae6cdf36aad295398e2487a
| 2021-04-05T19:52:47Z |
go
| 2021-04-06T00:09:35Z |
dagger/store.go
|
}
data, err := json.MarshalIndent(r, "", " ")
if err != nil {
return err
}
if err := os.WriteFile(p, data, 0600); err != nil {
return err
}
s.reindexDeployment(r)
return nil
}
func (s *Store) indexDeployment(r *DeploymentState) {
s.deployments[r.ID] = r
s.deploymentsByName[r.Name] = r
mapPath := func(i Input) {
if i.Type != InputTypeDir {
return
}
s.deploymentsByPath[i.Dir.Path] = append(s.deploymentsByPath[i.Dir.Path], r)
s.pathsByDeploymentID[r.ID] = append(s.pathsByDeploymentID[r.ID], i.Dir.Path)
}
mapPath(r.PlanSource)
for _, i := range r.Inputs {
mapPath(i.Value)
}
}
func (s *Store) deindexDeployment(id string) {
r, ok := s.deployments[id]
if !ok {
return
|
closed
|
dagger/dagger
|
https://github.com/dagger/dagger
| 276 |
Multiple deployments with the same name?
|
It appears multiple deployments can have the same name, which is confusing.
```
$ dagger up
7:50PM FTL system | multiple deployments match the current directory, select one with `--deployment` deploymentPath=/home/shykes/dagger deployments=[
"dagger",
"dagger-dev",
"dagger-dev"
]
```
```
$ ls ~/.dagger/store/
dagger dagger-dev react
```
|
https://github.com/dagger/dagger/issues/276
|
https://github.com/dagger/dagger/pull/279
|
1ae0ce65e90e4ff3b67317c957636b64058e1f35
|
7cf1163a2b7055a1dae6cdf36aad295398e2487a
| 2021-04-05T19:52:47Z |
go
| 2021-04-06T00:09:35Z |
dagger/store.go
|
}
delete(s.deployments, r.ID)
delete(s.deploymentsByName, r.Name)
for _, p := range s.pathsByDeploymentID[r.ID] {
deployments := []*DeploymentState{}
for _, d := range s.deploymentsByPath[p] {
if d.ID == r.ID {
continue
}
deployments = append(deployments, d)
}
s.deploymentsByPath[p] = deployments
}
delete(s.pathsByDeploymentID, r.ID)
}
func (s *Store) reindexDeployment(r *DeploymentState) {
s.deindexDeployment(r.ID)
s.indexDeployment(r)
}
func (s *Store) CreateDeployment(ctx context.Context, st *DeploymentState) error {
s.l.Lock()
defer s.l.Unlock()
if _, ok := s.deploymentsByName[st.Name]; ok {
return fmt.Errorf("%s: %w", st.Name, ErrDeploymentExist)
}
st.ID = uuid.New().String()
return s.syncDeployment(st)
}
type UpdateOpts struct{}
|
closed
|
dagger/dagger
|
https://github.com/dagger/dagger
| 276 |
Multiple deployments with the same name?
|
It appears multiple deployments can have the same name, which is confusing.
```
$ dagger up
7:50PM FTL system | multiple deployments match the current directory, select one with `--deployment` deploymentPath=/home/shykes/dagger deployments=[
"dagger",
"dagger-dev",
"dagger-dev"
]
```
```
$ ls ~/.dagger/store/
dagger dagger-dev react
```
|
https://github.com/dagger/dagger/issues/276
|
https://github.com/dagger/dagger/pull/279
|
1ae0ce65e90e4ff3b67317c957636b64058e1f35
|
7cf1163a2b7055a1dae6cdf36aad295398e2487a
| 2021-04-05T19:52:47Z |
go
| 2021-04-06T00:09:35Z |
dagger/store.go
|
func (s *Store) UpdateDeployment(ctx context.Context, r *DeploymentState, o *UpdateOpts) error {
s.l.Lock()
defer s.l.Unlock()
return s.syncDeployment(r)
}
type DeleteOpts struct{}
func (s *Store) DeleteDeployment(ctx context.Context, r *DeploymentState, o *DeleteOpts) error {
s.l.Lock()
defer s.l.Unlock()
if err := os.Remove(s.deploymentPath(r.Name)); err != nil {
return err
}
s.deindexDeployment(r.ID)
return nil
}
func (s *Store) LookupDeploymentByID(ctx context.Context, id string) (*DeploymentState, error) {
s.l.RLock()
defer s.l.RUnlock()
st, ok := s.deployments[id]
if !ok {
return nil, fmt.Errorf("%s: %w", id, ErrDeploymentNotExist)
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.