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
| 81,965 |
TypeError: join() missing 1 required positional argument: 'a' in ansible-galaxy
|
### Summary
```plaintext
# ansible-galaxy install willshersystems.sshd --force -vvv
ansible-galaxy [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.9.16 (main, Sep 8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
Starting galaxy role install process
Processing role willshersystems.sshd
Opened /root/.ansible/galaxy_token
- downloading role 'sshd', owned by willshersystems
- downloading role from https://github.com/willshersystems/ansible-sshd/archive/v0.21.0.tar.gz
- extracting willshersystems.sshd to /root/.ansible/roles/willshersystems.sshd
[WARNING]: Illegal filename '..': '..' is not allowed
ERROR! Unexpected Exception, this is probably a bug: join() missing 1 required positional argument: 'a'
the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
exit_code = cli.run()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 719, in run
return context.CLIARGS['func']()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 119, in method_wrapper
return wrapped_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1370, in execute_install
self._execute_install_role(role_requirements)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1469, in _execute_install_role
installed = role.install()
File "/usr/local/lib/python3.9/site-packages/ansible/galaxy/role.py", line 426, in install
setattr(member, attr, os.path.join(*n_final_parts))
TypeError: join() missing 1 required positional argument: 'a'
```
For some reason, the list `n_final_parts` doesn't contain any entries which makes this call crash:
```python
os.path.join(*n_final_parts)
```
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
$ ansible --version
ansible [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.9.16 (main, Feb 23 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
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) = vim
PAGER(env: PAGER) = less
```
### OS / Environment
Amazon Linux 2023
### Steps to Reproduce
not applicable
### Expected Results
I expect the ansible role to be installed
### Actual Results
```console
The installation process crashes, as mentioned above.
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/81965
|
https://github.com/ansible/ansible/pull/82165
|
b405958f7998efc2e1d03ecf2d22bcd9276b2533
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
| 2023-10-13T08:08:47Z |
python
| 2023-11-30T23:05:48Z |
lib/ansible/galaxy/role.py
|
"""
Downloads the archived role to a temp location based on role data
"""
if role_data:
if self.download_url is not None:
archive_url = self.download_url
elif "github_user" in role_data and "github_repo" in role_data:
archive_url = 'https://github.com/%s/%s/archive/%s.tar.gz' % (role_data["github_user"], role_data["github_repo"], self.version)
else:
archive_url = self.src
display.display("- downloading role from %s" % archive_url)
try:
url_file = open_url(archive_url, validate_certs=self._validate_certs, http_agent=user_agent())
temp_file = tempfile.NamedTemporaryFile(delete=False)
data = url_file.read()
while data:
temp_file.write(data)
data = url_file.read()
temp_file.close()
return temp_file.name
except Exception as e:
display.error(u"failed to download the file: %s" % to_text(e))
return False
def install(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 81,965 |
TypeError: join() missing 1 required positional argument: 'a' in ansible-galaxy
|
### Summary
```plaintext
# ansible-galaxy install willshersystems.sshd --force -vvv
ansible-galaxy [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.9.16 (main, Sep 8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
Starting galaxy role install process
Processing role willshersystems.sshd
Opened /root/.ansible/galaxy_token
- downloading role 'sshd', owned by willshersystems
- downloading role from https://github.com/willshersystems/ansible-sshd/archive/v0.21.0.tar.gz
- extracting willshersystems.sshd to /root/.ansible/roles/willshersystems.sshd
[WARNING]: Illegal filename '..': '..' is not allowed
ERROR! Unexpected Exception, this is probably a bug: join() missing 1 required positional argument: 'a'
the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
exit_code = cli.run()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 719, in run
return context.CLIARGS['func']()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 119, in method_wrapper
return wrapped_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1370, in execute_install
self._execute_install_role(role_requirements)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1469, in _execute_install_role
installed = role.install()
File "/usr/local/lib/python3.9/site-packages/ansible/galaxy/role.py", line 426, in install
setattr(member, attr, os.path.join(*n_final_parts))
TypeError: join() missing 1 required positional argument: 'a'
```
For some reason, the list `n_final_parts` doesn't contain any entries which makes this call crash:
```python
os.path.join(*n_final_parts)
```
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
$ ansible --version
ansible [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.9.16 (main, Feb 23 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
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) = vim
PAGER(env: PAGER) = less
```
### OS / Environment
Amazon Linux 2023
### Steps to Reproduce
not applicable
### Expected Results
I expect the ansible role to be installed
### Actual Results
```console
The installation process crashes, as mentioned above.
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/81965
|
https://github.com/ansible/ansible/pull/82165
|
b405958f7998efc2e1d03ecf2d22bcd9276b2533
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
| 2023-10-13T08:08:47Z |
python
| 2023-11-30T23:05:48Z |
lib/ansible/galaxy/role.py
|
if self.scm:
tmp_file = RoleRequirement.scm_archive_role(keep_scm_meta=context.CLIARGS['keep_scm_meta'], **self.spec)
elif self.src:
if os.path.isfile(self.src):
tmp_file = self.src
elif '://' in self.src:
role_data = self.src
tmp_file = self.fetch(role_data)
else:
role_data = self.api.lookup_role_by_name(self.src)
if not role_data:
raise AnsibleError("- sorry, %s was not found on %s." % (self.src, self.api.api_server))
if role_data.get('role_type') == 'APP':
display.warning("%s is a Container App role, and should only be installed using Ansible "
"Container" % self.name)
role_versions = self.api.fetch_role_related('versions', role_data['id'])
if not self.version:
if len(role_versions) > 0:
loose_versions = [LooseVersion(a.get('name', None)) for a in role_versions]
try:
loose_versions.sort()
except TypeError:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 81,965 |
TypeError: join() missing 1 required positional argument: 'a' in ansible-galaxy
|
### Summary
```plaintext
# ansible-galaxy install willshersystems.sshd --force -vvv
ansible-galaxy [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.9.16 (main, Sep 8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
Starting galaxy role install process
Processing role willshersystems.sshd
Opened /root/.ansible/galaxy_token
- downloading role 'sshd', owned by willshersystems
- downloading role from https://github.com/willshersystems/ansible-sshd/archive/v0.21.0.tar.gz
- extracting willshersystems.sshd to /root/.ansible/roles/willshersystems.sshd
[WARNING]: Illegal filename '..': '..' is not allowed
ERROR! Unexpected Exception, this is probably a bug: join() missing 1 required positional argument: 'a'
the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
exit_code = cli.run()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 719, in run
return context.CLIARGS['func']()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 119, in method_wrapper
return wrapped_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1370, in execute_install
self._execute_install_role(role_requirements)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1469, in _execute_install_role
installed = role.install()
File "/usr/local/lib/python3.9/site-packages/ansible/galaxy/role.py", line 426, in install
setattr(member, attr, os.path.join(*n_final_parts))
TypeError: join() missing 1 required positional argument: 'a'
```
For some reason, the list `n_final_parts` doesn't contain any entries which makes this call crash:
```python
os.path.join(*n_final_parts)
```
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
$ ansible --version
ansible [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.9.16 (main, Feb 23 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
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) = vim
PAGER(env: PAGER) = less
```
### OS / Environment
Amazon Linux 2023
### Steps to Reproduce
not applicable
### Expected Results
I expect the ansible role to be installed
### Actual Results
```console
The installation process crashes, as mentioned above.
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/81965
|
https://github.com/ansible/ansible/pull/82165
|
b405958f7998efc2e1d03ecf2d22bcd9276b2533
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
| 2023-10-13T08:08:47Z |
python
| 2023-11-30T23:05:48Z |
lib/ansible/galaxy/role.py
|
raise AnsibleError(
'Unable to compare role versions (%s) to determine the most recent version due to incompatible version formats. '
'Please contact the role author to resolve versioning conflicts, or specify an explicit role version to '
'install.' % ', '.join([v.vstring for v in loose_versions])
)
self.version = to_text(loose_versions[-1])
elif role_data.get('github_branch', None):
self.version = role_data['github_branch']
else:
self.version = 'master'
elif self.version != 'master':
if role_versions and to_text(self.version) not in [a.get('name', None) for a in role_versions]:
raise AnsibleError("- the specified version (%s) of %s was not found in the list of available versions (%s)." % (self.version,
self.name,
role_versions))
for role_version in role_versions:
if role_version['name'] == self.version and 'source' in role_version:
self.src = role_version['source']
if role_version['name'] == self.version and 'download_url' in role_version:
self.download_url = role_version['download_url']
tmp_file = self.fetch(role_data)
else:
raise AnsibleError("No valid role data found")
if tmp_file:
display.debug("installing from %s" % tmp_file)
if not tarfile.is_tarfile(tmp_file):
raise AnsibleError("the downloaded file does not appear to be a valid tar archive.")
else:
role_tar_file = tarfile.open(tmp_file, "r")
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 81,965 |
TypeError: join() missing 1 required positional argument: 'a' in ansible-galaxy
|
### Summary
```plaintext
# ansible-galaxy install willshersystems.sshd --force -vvv
ansible-galaxy [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.9.16 (main, Sep 8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
Starting galaxy role install process
Processing role willshersystems.sshd
Opened /root/.ansible/galaxy_token
- downloading role 'sshd', owned by willshersystems
- downloading role from https://github.com/willshersystems/ansible-sshd/archive/v0.21.0.tar.gz
- extracting willshersystems.sshd to /root/.ansible/roles/willshersystems.sshd
[WARNING]: Illegal filename '..': '..' is not allowed
ERROR! Unexpected Exception, this is probably a bug: join() missing 1 required positional argument: 'a'
the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
exit_code = cli.run()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 719, in run
return context.CLIARGS['func']()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 119, in method_wrapper
return wrapped_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1370, in execute_install
self._execute_install_role(role_requirements)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1469, in _execute_install_role
installed = role.install()
File "/usr/local/lib/python3.9/site-packages/ansible/galaxy/role.py", line 426, in install
setattr(member, attr, os.path.join(*n_final_parts))
TypeError: join() missing 1 required positional argument: 'a'
```
For some reason, the list `n_final_parts` doesn't contain any entries which makes this call crash:
```python
os.path.join(*n_final_parts)
```
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
$ ansible --version
ansible [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.9.16 (main, Feb 23 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
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) = vim
PAGER(env: PAGER) = less
```
### OS / Environment
Amazon Linux 2023
### Steps to Reproduce
not applicable
### Expected Results
I expect the ansible role to be installed
### Actual Results
```console
The installation process crashes, as mentioned above.
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/81965
|
https://github.com/ansible/ansible/pull/82165
|
b405958f7998efc2e1d03ecf2d22bcd9276b2533
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
| 2023-10-13T08:08:47Z |
python
| 2023-11-30T23:05:48Z |
lib/ansible/galaxy/role.py
|
meta_file = None
members = role_tar_file.getmembers()
for member in members:
for meta_main in self.META_MAIN:
if meta_main in member.name:
meta_parent_dir = os.path.dirname(os.path.dirname(member.name))
if not meta_file:
archive_parent_dir = meta_parent_dir
meta_file = member
else:
if len(meta_parent_dir) < len(archive_parent_dir):
archive_parent_dir = meta_parent_dir
meta_file = member
if not meta_file:
raise AnsibleError("this role does not appear to have a meta/main.yml file.")
else:
try:
self._metadata = yaml_load(role_tar_file.extractfile(meta_file))
except Exception:
raise AnsibleError("this role does not appear to have a valid meta/main.yml file.")
paths = self.paths
if self.path != paths[0]:
paths[:0] = self.path
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 81,965 |
TypeError: join() missing 1 required positional argument: 'a' in ansible-galaxy
|
### Summary
```plaintext
# ansible-galaxy install willshersystems.sshd --force -vvv
ansible-galaxy [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.9.16 (main, Sep 8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
Starting galaxy role install process
Processing role willshersystems.sshd
Opened /root/.ansible/galaxy_token
- downloading role 'sshd', owned by willshersystems
- downloading role from https://github.com/willshersystems/ansible-sshd/archive/v0.21.0.tar.gz
- extracting willshersystems.sshd to /root/.ansible/roles/willshersystems.sshd
[WARNING]: Illegal filename '..': '..' is not allowed
ERROR! Unexpected Exception, this is probably a bug: join() missing 1 required positional argument: 'a'
the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
exit_code = cli.run()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 719, in run
return context.CLIARGS['func']()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 119, in method_wrapper
return wrapped_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1370, in execute_install
self._execute_install_role(role_requirements)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1469, in _execute_install_role
installed = role.install()
File "/usr/local/lib/python3.9/site-packages/ansible/galaxy/role.py", line 426, in install
setattr(member, attr, os.path.join(*n_final_parts))
TypeError: join() missing 1 required positional argument: 'a'
```
For some reason, the list `n_final_parts` doesn't contain any entries which makes this call crash:
```python
os.path.join(*n_final_parts)
```
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
$ ansible --version
ansible [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.9.16 (main, Feb 23 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
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) = vim
PAGER(env: PAGER) = less
```
### OS / Environment
Amazon Linux 2023
### Steps to Reproduce
not applicable
### Expected Results
I expect the ansible role to be installed
### Actual Results
```console
The installation process crashes, as mentioned above.
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/81965
|
https://github.com/ansible/ansible/pull/82165
|
b405958f7998efc2e1d03ecf2d22bcd9276b2533
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
| 2023-10-13T08:08:47Z |
python
| 2023-11-30T23:05:48Z |
lib/ansible/galaxy/role.py
|
paths_len = len(paths)
for idx, path in enumerate(paths):
self.path = path
display.display("- extracting %s to %s" % (self.name, self.path))
try:
if os.path.exists(self.path):
if not os.path.isdir(self.path):
raise AnsibleError("the specified roles path exists and is not a directory.")
elif not context.CLIARGS.get("force", False):
raise AnsibleError("the specified role %s appears to already exist. Use --force to replace it." % self.name)
else:
if not self.remove():
raise AnsibleError("%s doesn't appear to contain a role.\n please remove this directory manually if you really "
"want to put the role here." % self.path)
else:
os.makedirs(self.path)
for member in members:
if member.isreg() or member.issym():
for attr in ('name', 'linkname'):
attr_value = getattr(member, attr, None)
if not attr_value:
continue
n_attr_value = to_native(attr_value)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 81,965 |
TypeError: join() missing 1 required positional argument: 'a' in ansible-galaxy
|
### Summary
```plaintext
# ansible-galaxy install willshersystems.sshd --force -vvv
ansible-galaxy [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.9.16 (main, Sep 8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
Starting galaxy role install process
Processing role willshersystems.sshd
Opened /root/.ansible/galaxy_token
- downloading role 'sshd', owned by willshersystems
- downloading role from https://github.com/willshersystems/ansible-sshd/archive/v0.21.0.tar.gz
- extracting willshersystems.sshd to /root/.ansible/roles/willshersystems.sshd
[WARNING]: Illegal filename '..': '..' is not allowed
ERROR! Unexpected Exception, this is probably a bug: join() missing 1 required positional argument: 'a'
the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
exit_code = cli.run()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 719, in run
return context.CLIARGS['func']()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 119, in method_wrapper
return wrapped_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1370, in execute_install
self._execute_install_role(role_requirements)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1469, in _execute_install_role
installed = role.install()
File "/usr/local/lib/python3.9/site-packages/ansible/galaxy/role.py", line 426, in install
setattr(member, attr, os.path.join(*n_final_parts))
TypeError: join() missing 1 required positional argument: 'a'
```
For some reason, the list `n_final_parts` doesn't contain any entries which makes this call crash:
```python
os.path.join(*n_final_parts)
```
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
$ ansible --version
ansible [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.9.16 (main, Feb 23 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
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) = vim
PAGER(env: PAGER) = less
```
### OS / Environment
Amazon Linux 2023
### Steps to Reproduce
not applicable
### Expected Results
I expect the ansible role to be installed
### Actual Results
```console
The installation process crashes, as mentioned above.
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/81965
|
https://github.com/ansible/ansible/pull/82165
|
b405958f7998efc2e1d03ecf2d22bcd9276b2533
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
| 2023-10-13T08:08:47Z |
python
| 2023-11-30T23:05:48Z |
lib/ansible/galaxy/role.py
|
n_archive_parent_dir = to_native(archive_parent_dir)
n_parts = n_attr_value.replace(n_archive_parent_dir, "", 1).split(os.sep)
n_final_parts = []
for n_part in n_parts:
#
if not n_part:
continue
if n_part == '..':
display.warning(f"Illegal filename '{n_part}': '..' is not allowed")
continue
if n_part.startswith('~'):
display.warning(f"Illegal filename '{n_part}': names cannot start with '~'")
continue
if '$' in n_part:
display.warning(f"Illegal filename '{n_part}': names cannot contain '$'")
continue
n_final_parts.append(n_part)
setattr(member, attr, os.path.join(*n_final_parts))
if _check_working_data_filter():
role_tar_file.extract(member, to_native(self.path), filter='data')
else:
role_tar_file.extract(member, to_native(self.path))
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 81,965 |
TypeError: join() missing 1 required positional argument: 'a' in ansible-galaxy
|
### Summary
```plaintext
# ansible-galaxy install willshersystems.sshd --force -vvv
ansible-galaxy [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.9.16 (main, Sep 8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
Starting galaxy role install process
Processing role willshersystems.sshd
Opened /root/.ansible/galaxy_token
- downloading role 'sshd', owned by willshersystems
- downloading role from https://github.com/willshersystems/ansible-sshd/archive/v0.21.0.tar.gz
- extracting willshersystems.sshd to /root/.ansible/roles/willshersystems.sshd
[WARNING]: Illegal filename '..': '..' is not allowed
ERROR! Unexpected Exception, this is probably a bug: join() missing 1 required positional argument: 'a'
the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
exit_code = cli.run()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 719, in run
return context.CLIARGS['func']()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 119, in method_wrapper
return wrapped_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1370, in execute_install
self._execute_install_role(role_requirements)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1469, in _execute_install_role
installed = role.install()
File "/usr/local/lib/python3.9/site-packages/ansible/galaxy/role.py", line 426, in install
setattr(member, attr, os.path.join(*n_final_parts))
TypeError: join() missing 1 required positional argument: 'a'
```
For some reason, the list `n_final_parts` doesn't contain any entries which makes this call crash:
```python
os.path.join(*n_final_parts)
```
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
$ ansible --version
ansible [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.9.16 (main, Feb 23 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
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) = vim
PAGER(env: PAGER) = less
```
### OS / Environment
Amazon Linux 2023
### Steps to Reproduce
not applicable
### Expected Results
I expect the ansible role to be installed
### Actual Results
```console
The installation process crashes, as mentioned above.
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/81965
|
https://github.com/ansible/ansible/pull/82165
|
b405958f7998efc2e1d03ecf2d22bcd9276b2533
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
| 2023-10-13T08:08:47Z |
python
| 2023-11-30T23:05:48Z |
lib/ansible/galaxy/role.py
|
self._write_galaxy_install_info()
break
except OSError as e:
if e.errno == errno.EACCES and idx < paths_len - 1:
continue
raise AnsibleError("Could not update files in %s: %s" % (self.path, to_native(e)))
display.display("- %s was installed successfully" % str(self))
if not (self.src and os.path.isfile(self.src)):
try:
os.unlink(tmp_file)
except (OSError, IOError) as e:
display.warning(u"Unable to remove tmp file (%s): %s" % (tmp_file, to_text(e)))
return True
return False
@property
def spec(self):
"""
Returns role spec info
{
'scm': 'git',
'src': 'http://git.example.com/repos/repo.git',
'version': 'v1.0',
'name': 'repo'
}
"""
return dict(scm=self.scm, src=self.src, version=self.version, name=self.name)
@property
def requirements(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 81,965 |
TypeError: join() missing 1 required positional argument: 'a' in ansible-galaxy
|
### Summary
```plaintext
# ansible-galaxy install willshersystems.sshd --force -vvv
ansible-galaxy [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.9.16 (main, Sep 8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
Starting galaxy role install process
Processing role willshersystems.sshd
Opened /root/.ansible/galaxy_token
- downloading role 'sshd', owned by willshersystems
- downloading role from https://github.com/willshersystems/ansible-sshd/archive/v0.21.0.tar.gz
- extracting willshersystems.sshd to /root/.ansible/roles/willshersystems.sshd
[WARNING]: Illegal filename '..': '..' is not allowed
ERROR! Unexpected Exception, this is probably a bug: join() missing 1 required positional argument: 'a'
the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
exit_code = cli.run()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 719, in run
return context.CLIARGS['func']()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 119, in method_wrapper
return wrapped_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1370, in execute_install
self._execute_install_role(role_requirements)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1469, in _execute_install_role
installed = role.install()
File "/usr/local/lib/python3.9/site-packages/ansible/galaxy/role.py", line 426, in install
setattr(member, attr, os.path.join(*n_final_parts))
TypeError: join() missing 1 required positional argument: 'a'
```
For some reason, the list `n_final_parts` doesn't contain any entries which makes this call crash:
```python
os.path.join(*n_final_parts)
```
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
$ ansible --version
ansible [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.9.16 (main, Feb 23 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
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) = vim
PAGER(env: PAGER) = less
```
### OS / Environment
Amazon Linux 2023
### Steps to Reproduce
not applicable
### Expected Results
I expect the ansible role to be installed
### Actual Results
```console
The installation process crashes, as mentioned above.
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/81965
|
https://github.com/ansible/ansible/pull/82165
|
b405958f7998efc2e1d03ecf2d22bcd9276b2533
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
| 2023-10-13T08:08:47Z |
python
| 2023-11-30T23:05:48Z |
lib/ansible/galaxy/role.py
|
"""
Returns role requirements
"""
if self._requirements is None:
self._requirements = []
for meta_requirements in self.META_REQUIREMENTS:
meta_path = os.path.join(self.path, meta_requirements)
if os.path.isfile(meta_path):
try:
f = open(meta_path, 'r')
self._requirements = yaml_load(f)
except Exception:
display.vvvvv("Unable to load requirements for %s" % self.name)
finally:
f.close()
break
if not isinstance(self._requirements, MutableSequence):
raise AnsibleParserError(f"Expected role dependencies to be a list. Role {self} has meta/requirements.yml {self._requirements}")
return self._requirements
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 81,965 |
TypeError: join() missing 1 required positional argument: 'a' in ansible-galaxy
|
### Summary
```plaintext
# ansible-galaxy install willshersystems.sshd --force -vvv
ansible-galaxy [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.9.16 (main, Sep 8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
Starting galaxy role install process
Processing role willshersystems.sshd
Opened /root/.ansible/galaxy_token
- downloading role 'sshd', owned by willshersystems
- downloading role from https://github.com/willshersystems/ansible-sshd/archive/v0.21.0.tar.gz
- extracting willshersystems.sshd to /root/.ansible/roles/willshersystems.sshd
[WARNING]: Illegal filename '..': '..' is not allowed
ERROR! Unexpected Exception, this is probably a bug: join() missing 1 required positional argument: 'a'
the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
exit_code = cli.run()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 719, in run
return context.CLIARGS['func']()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 119, in method_wrapper
return wrapped_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1370, in execute_install
self._execute_install_role(role_requirements)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1469, in _execute_install_role
installed = role.install()
File "/usr/local/lib/python3.9/site-packages/ansible/galaxy/role.py", line 426, in install
setattr(member, attr, os.path.join(*n_final_parts))
TypeError: join() missing 1 required positional argument: 'a'
```
For some reason, the list `n_final_parts` doesn't contain any entries which makes this call crash:
```python
os.path.join(*n_final_parts)
```
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
$ ansible --version
ansible [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.9.16 (main, Feb 23 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
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) = vim
PAGER(env: PAGER) = less
```
### OS / Environment
Amazon Linux 2023
### Steps to Reproduce
not applicable
### Expected Results
I expect the ansible role to be installed
### Actual Results
```console
The installation process crashes, as mentioned above.
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/81965
|
https://github.com/ansible/ansible/pull/82165
|
b405958f7998efc2e1d03ecf2d22bcd9276b2533
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
| 2023-10-13T08:08:47Z |
python
| 2023-11-30T23:05:48Z |
test/integration/targets/ansible-galaxy-role/files/create-role-archive.py
|
"""Create a role archive which overwrites an arbitrary file."""
from __future__ import annotations
import argparse
import pathlib
import tarfile
import tempfile
def main() -> None:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 81,965 |
TypeError: join() missing 1 required positional argument: 'a' in ansible-galaxy
|
### Summary
```plaintext
# ansible-galaxy install willshersystems.sshd --force -vvv
ansible-galaxy [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-galaxy
python version = 3.9.16 (main, Sep 8 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
Starting galaxy role install process
Processing role willshersystems.sshd
Opened /root/.ansible/galaxy_token
- downloading role 'sshd', owned by willshersystems
- downloading role from https://github.com/willshersystems/ansible-sshd/archive/v0.21.0.tar.gz
- extracting willshersystems.sshd to /root/.ansible/roles/willshersystems.sshd
[WARNING]: Illegal filename '..': '..' is not allowed
ERROR! Unexpected Exception, this is probably a bug: join() missing 1 required positional argument: 'a'
the full traceback was:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
exit_code = cli.run()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 719, in run
return context.CLIARGS['func']()
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 119, in method_wrapper
return wrapped_method(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1370, in execute_install
self._execute_install_role(role_requirements)
File "/usr/local/lib/python3.9/site-packages/ansible/cli/galaxy.py", line 1469, in _execute_install_role
installed = role.install()
File "/usr/local/lib/python3.9/site-packages/ansible/galaxy/role.py", line 426, in install
setattr(member, attr, os.path.join(*n_final_parts))
TypeError: join() missing 1 required positional argument: 'a'
```
For some reason, the list `n_final_parts` doesn't contain any entries which makes this call crash:
```python
os.path.join(*n_final_parts)
```
### Issue Type
Bug Report
### Component Name
ansible-galaxy
### Ansible Version
```console
$ ansible --version
ansible [core 2.15.5]
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.9.16 (main, Feb 23 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
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) = vim
PAGER(env: PAGER) = less
```
### OS / Environment
Amazon Linux 2023
### Steps to Reproduce
not applicable
### Expected Results
I expect the ansible role to be installed
### Actual Results
```console
The installation process crashes, as mentioned above.
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/81965
|
https://github.com/ansible/ansible/pull/82165
|
b405958f7998efc2e1d03ecf2d22bcd9276b2533
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
| 2023-10-13T08:08:47Z |
python
| 2023-11-30T23:05:48Z |
test/integration/targets/ansible-galaxy-role/files/create-role-archive.py
|
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('archive', type=pathlib.Path, help='archive to create')
parser.add_argument('content', type=pathlib.Path, help='content to write')
parser.add_argument('target', type=pathlib.Path, help='file to overwrite')
args = parser.parse_args()
create_archive(args.archive, args.content, args.target)
def create_archive(archive_path: pathlib.Path, content_path: pathlib.Path, target_path: pathlib.Path) -> None:
with (
tarfile.open(name=archive_path, mode='w') as role_archive,
tempfile.TemporaryDirectory() as temp_dir_name,
):
temp_dir_path = pathlib.Path(temp_dir_name)
meta_main_path = temp_dir_path / 'meta' / 'main.yml'
meta_main_path.parent.mkdir()
meta_main_path.write_text('')
symlink_path = temp_dir_path / 'symlink'
symlink_path.symlink_to(target_path)
role_archive.add(meta_main_path)
role_archive.add(symlink_path)
content_tarinfo = role_archive.gettarinfo(content_path, str(symlink_path))
with content_path.open('rb') as content_file:
role_archive.addfile(content_tarinfo, content_file)
if __name__ == '__main__':
main()
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
from __future__ import annotations
import os
import pty
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
import time
import json
import signal
import subprocess
import sys
import termios
import traceback
from ansible import constants as C
from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVariable, AnsibleConnectionFailure, AnsibleActionFail, AnsibleActionSkip
from ansible.executor.task_result import TaskResult
from ansible.executor.module_common import get_action_args_with_defaults
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.module_utils.six import binary_type
from ansible.module_utils.common.text.converters import to_text, to_native
from ansible.module_utils.connection import write_to_file_descriptor
from ansible.playbook.conditional import Conditional
from ansible.playbook.task import Task
from ansible.plugins import get_plugin_class
from ansible.plugins.loader import become_loader, cliconf_loader, connection_loader, httpapi_loader, netconf_loader, terminal_loader
from ansible.template import Templar
from ansible.utils.collection_loader import AnsibleCollectionConfig
from ansible.utils.listify import listify_lookup_plugin_terms
from ansible.utils.unsafe_proxy import to_unsafe_text, wrap_var
from ansible.vars.clean import namespace_facts, clean_facts
from ansible.utils.display import Display
from ansible.utils.vars import combine_vars, isidentifier
display = Display()
RETURN_VARS = [x for x in C.MAGIC_VARIABLE_MAPPING.items() if 'become' not in x and '_pass' not in x]
__all__ = ['TaskExecutor']
class TaskTimeoutError(BaseException):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
pass
def task_timeout(signum, frame):
raise TaskTimeoutError
def remove_omit(task_args, omit_token):
'''
Remove args with a value equal to the ``omit_token`` recursively
to align with now having suboptions in the argument_spec
'''
if not isinstance(task_args, dict):
return task_args
new_args = {}
for i in task_args.items():
if i[1] == omit_token:
continue
elif isinstance(i[1], dict):
new_args[i[0]] = remove_omit(i[1], omit_token)
elif isinstance(i[1], list):
new_args[i[0]] = [remove_omit(v, omit_token) for v in i[1]]
else:
new_args[i[0]] = i[1]
return new_args
class TaskExecutor:
'''
This is the main worker class for the executor pipeline, which
handles loading an action plugin to actually dispatch the task to
a given host. This class roughly corresponds to the old Runner()
class.
'''
def __init__(self, host, task, job_vars, play_context, new_stdin, loader, shared_loader_obj, final_q, variable_manager):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
self._host = host
self._task = task
self._job_vars = job_vars
self._play_context = play_context
self._new_stdin = new_stdin
self._loader = loader
self._shared_loader_obj = shared_loader_obj
self._connection = None
self._final_q = final_q
self._variable_manager = variable_manager
self._loop_eval_error = None
self._task.squash()
def run(self):
'''
The main executor entrypoint, where we determine if the specified
task requires looping and either runs the task with self._run_loop()
or self._execute(). After that, the returned results are parsed and
returned as a dict.
'''
display.debug("in run() - task %s" % self._task._uuid)
try:
try:
items = self._get_loop_items()
except AnsibleUndefinedVariable as e:
items = None
self._loop_eval_error = e
if items is not None:
if len(items) > 0:
item_results = self._run_loop(items)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
res = dict(results=item_results)
res['skipped'] = True
for item in item_results:
if 'changed' in item and item['changed'] and not res.get('changed'):
res['changed'] = True
if res['skipped'] and ('skipped' not in item or ('skipped' in item and not item['skipped'])):
res['skipped'] = False
if 'failed' in item and item['failed']:
item_ignore = item.pop('_ansible_ignore_errors')
if not res.get('failed'):
res['failed'] = True
res['msg'] = 'One or more items failed'
self._task.ignore_errors = item_ignore
elif self._task.ignore_errors and not item_ignore:
self._task.ignore_errors = item_ignore
if 'unreachable' in item and item['unreachable']:
item_ignore_unreachable = item.pop('_ansible_ignore_unreachable')
if not res.get('unreachable'):
self._task.ignore_unreachable = item_ignore_unreachable
elif self._task.ignore_unreachable and not item_ignore_unreachable:
self._task.ignore_unreachable = item_ignore_unreachable
for array in ['warnings', 'deprecations']:
if array in item and item[array]:
if array not in res:
res[array] = []
if not isinstance(item[array], list):
item[array] = [item[array]]
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
res[array] = res[array] + item[array]
del item[array]
if not res.get('failed', False):
res['msg'] = 'All items completed'
if res['skipped']:
res['msg'] = 'All items skipped'
else:
res = dict(changed=False, skipped=True, skipped_reason='No items in the list', results=[])
else:
display.debug("calling self._execute()")
res = self._execute()
display.debug("_execute() done")
if 'changed' not in res:
res['changed'] = False
def _clean_res(res, errors='surrogate_or_strict'):
if isinstance(res, binary_type):
return to_unsafe_text(res, errors=errors)
elif isinstance(res, dict):
for k in res:
try:
res[k] = _clean_res(res[k], errors=errors)
except UnicodeError:
if k == 'diff':
display.warning("We were unable to decode all characters in the module return data."
" Replaced some in an effort to return as much as possible")
res[k] = _clean_res(res[k], errors='surrogate_then_replace')
else:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
raise
elif isinstance(res, list):
for idx, item in enumerate(res):
res[idx] = _clean_res(item, errors=errors)
return res
display.debug("dumping result to json")
res = _clean_res(res)
display.debug("done dumping result, returning")
return res
except AnsibleError as e:
return dict(failed=True, msg=wrap_var(to_text(e, nonstring='simplerepr')), _ansible_no_log=self._play_context.no_log)
except Exception as e:
return dict(failed=True, msg=wrap_var('Unexpected failure during module execution: %s' % (to_native(e, nonstring='simplerepr'))),
exception=to_text(traceback.format_exc()), stdout='', _ansible_no_log=self._play_context.no_log)
finally:
try:
self._connection.close()
except AttributeError:
pass
except Exception as e:
display.debug(u"error closing connection: %s" % to_text(e))
def _get_loop_items(self):
'''
Loads a lookup plugin to handle the with_* portion of a task (if specified),
and returns the items result.
'''
self._job_vars['ansible_search_path'] = self._task.get_search_path()
if self._loader.get_basedir() not in self._job_vars['ansible_search_path']:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
self._job_vars['ansible_search_path'].append(self._loader.get_basedir())
templar = Templar(loader=self._loader, variables=self._job_vars)
items = None
if self._task.loop_with:
if self._task.loop_with in self._shared_loader_obj.lookup_loader:
fail = bool(self._task.loop_with != 'first_found')
loop_terms = listify_lookup_plugin_terms(terms=self._task.loop, templar=templar, fail_on_undefined=fail, convert_bare=False)
mylookup = self._shared_loader_obj.lookup_loader.get(self._task.loop_with, loader=self._loader, templar=templar)
for subdir in ['template', 'var', 'file']:
if subdir in self._task.action:
break
setattr(mylookup, '_subdir', subdir + 's')
items = wrap_var(mylookup.run(terms=loop_terms, variables=self._job_vars, wantlist=True))
else:
raise AnsibleError("Unexpected failure in finding the lookup named '%s' in the available lookup plugins" % self._task.loop_with)
elif self._task.loop is not None:
items = templar.template(self._task.loop)
if not isinstance(items, list):
raise AnsibleError(
"Invalid data passed to 'loop', it requires a list, got this instead: %s."
" Hint: If you passed a list/dict of just one element,"
" try adding wantlist=True to your lookup invocation or use q/query instead of lookup." % items
)
return items
def _run_loop(self, items):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
'''
Runs the task with the loop items specified and collates the result
into an array named 'results' which is inserted into the final result
along with the item for which the loop ran.
'''
task_vars = self._job_vars
templar = Templar(loader=self._loader, variables=task_vars)
self._task.loop_control.post_validate(templar=templar)
loop_var = self._task.loop_control.loop_var
index_var = self._task.loop_control.index_var
loop_pause = self._task.loop_control.pause
extended = self._task.loop_control.extended
extended_allitems = self._task.loop_control.extended_allitems
label = self._task.loop_control.label or '{{' + loop_var + '}}'
if loop_var in task_vars:
display.warning(u"%s: The loop variable '%s' is already in use. "
u"You should set the `loop_var` value in the `loop_control` option for the task"
u" to something else to avoid variable collisions and unexpected behavior." % (self._task, loop_var))
ran_once = False
task_fields = None
no_log = False
items_len = len(items)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
results = []
for item_index, item in enumerate(items):
task_vars['ansible_loop_var'] = loop_var
task_vars[loop_var] = item
if index_var:
task_vars['ansible_index_var'] = index_var
task_vars[index_var] = item_index
if extended:
task_vars['ansible_loop'] = {
'index': item_index + 1,
'index0': item_index,
'first': item_index == 0,
'last': item_index + 1 == items_len,
'length': items_len,
'revindex': items_len - item_index,
'revindex0': items_len - item_index - 1,
}
if extended_allitems:
task_vars['ansible_loop']['allitems'] = items
try:
task_vars['ansible_loop']['nextitem'] = items[item_index + 1]
except IndexError:
pass
if item_index - 1 >= 0:
task_vars['ansible_loop']['previtem'] = items[item_index - 1]
templar.available_variables = task_vars
if loop_pause and ran_once:
time.sleep(loop_pause)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
else:
ran_once = True
try:
tmp_task = self._task.copy(exclude_parent=True, exclude_tasks=True)
tmp_task._parent = self._task._parent
tmp_play_context = self._play_context.copy()
except AnsibleParserError as e:
results.append(dict(failed=True, msg=to_text(e)))
continue
(self._task, tmp_task) = (tmp_task, self._task)
(self._play_context, tmp_play_context) = (tmp_play_context, self._play_context)
res = self._execute(variables=task_vars)
task_fields = self._task.dump_attrs()
(self._task, tmp_task) = (tmp_task, self._task)
(self._play_context, tmp_play_context) = (tmp_play_context, self._play_context)
no_log = no_log or tmp_task.no_log
res[loop_var] = item
res['ansible_loop_var'] = loop_var
if index_var:
res[index_var] = item_index
res['ansible_index_var'] = index_var
if extended:
res['ansible_loop'] = task_vars['ansible_loop']
res['_ansible_item_result'] = True
res['_ansible_ignore_errors'] = task_fields.get('ignore_errors')
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
res['_ansible_ignore_unreachable'] = task_fields.get('ignore_unreachable')
try:
res['_ansible_item_label'] = templar.template(label)
except AnsibleUndefinedVariable as e:
res.update({
'failed': True,
'msg': 'Failed to template loop_control.label: %s' % to_text(e)
})
tr = TaskResult(
self._host.name,
self._task._uuid,
res,
task_fields=task_fields,
)
if tr.is_failed() or tr.is_unreachable():
self._final_q.send_callback('v2_runner_item_on_failed', tr)
elif tr.is_skipped():
self._final_q.send_callback('v2_runner_item_on_skipped', tr)
else:
if getattr(self._task, 'diff', False):
self._final_q.send_callback('v2_on_file_diff', tr)
if self._task.action not in C._ACTION_INVENTORY_TASKS:
self._final_q.send_callback('v2_runner_item_on_ok', tr)
results.append(res)
del task_vars[loop_var]
if self._connection:
clear_plugins = {
'connection': self._connection._load_name,
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
'shell': self._connection._shell._load_name
}
if self._connection.become:
clear_plugins['become'] = self._connection.become._load_name
for plugin_type, plugin_name in clear_plugins.items():
for var in C.config.get_plugin_vars(plugin_type, plugin_name):
if var in task_vars and var not in self._job_vars:
del task_vars[var]
self._task.no_log = no_log
self._task.run_once = task_fields.get('run_once')
self._task.action = task_fields.get('action')
return results
def _calculate_delegate_to(self, templar, variables):
"""This method is responsible for effectively pre-validating Task.delegate_to and will
happen before Task.post_validate is executed
"""
delegated_vars, delegated_host_name = self._variable_manager.get_delegated_vars_and_hostname(
templar,
self._task,
variables
)
if delegated_host_name:
self._task.delegate_to = delegated_host_name
variables.update(delegated_vars)
def _execute(self, variables=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
'''
The primary workhorse of the executor system, this runs the task
on the specified host (which may be the delegated_to host) and handles
the retry/until and block rescue/always execution
'''
if variables is None:
variables = self._job_vars
templar = Templar(loader=self._loader, variables=variables)
self._calculate_delegate_to(templar, variables)
context_validation_error = None
tempvars = variables.copy()
try:
self._play_context = self._play_context.set_task_and_variable_override(task=self._task, variables=variables, templar=templar)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
self._play_context.post_validate(templar=templar)
if not self._play_context.remote_addr:
self._play_context.remote_addr = self._host.address
self._play_context.update_vars(tempvars)
except AnsibleError as e:
context_validation_error = e
no_log = self._play_context.no_log
try:
conditional_result, false_condition = self._task.evaluate_conditional_with_result(templar, tempvars)
if not conditional_result:
display.debug("when evaluation is False, skipping this task")
return dict(changed=False, skipped=True, skip_reason='Conditional result was False',
false_condition=false_condition, _ansible_no_log=no_log)
except AnsibleError as e:
if self._loop_eval_error is not None:
display.v(to_text(e))
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
raise self._loop_eval_error
raise
if self._loop_eval_error is not None:
raise self._loop_eval_error
if context_validation_error is not None:
raiseit = True
if self._task.delegate_to:
if isinstance(context_validation_error, AnsibleUndefinedVariable):
raiseit = False
elif isinstance(context_validation_error, AnsibleParserError):
orig_exc = getattr(context_validation_error, 'orig_exc', None)
if isinstance(orig_exc, AnsibleUndefinedVariable):
raiseit = False
if raiseit:
raise context_validation_error
templar.available_variables = tempvars
if self._task.action in C._ACTION_INCLUDE_TASKS:
include_args = self._task.args.copy()
include_file = include_args.pop('_raw_params', None)
if not include_file:
return dict(failed=True, msg="No include file was specified to the include")
include_file = templar.template(include_file)
return dict(include=include_file, include_args=include_args)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
elif self._task.action in C._ACTION_INCLUDE_ROLE:
include_args = self._task.args.copy()
return dict(include_args=include_args)
try:
self._task.post_validate(templar=templar)
except AnsibleError:
raise
except Exception:
return dict(changed=False, failed=True, _ansible_no_log=no_log, exception=to_text(traceback.format_exc()))
if '_variable_params' in self._task.args:
variable_params = self._task.args.pop('_variable_params')
if isinstance(variable_params, dict):
if C.INJECT_FACTS_AS_VARS:
display.warning("Using a variable for a task's 'args' is unsafe in some situations "
"(see https://docs.ansible.com/ansible/devel/reference_appendices/faq.html#argsplat-unsafe)")
variable_params.update(self._task.args)
self._task.args = variable_params
else:
raise AnsibleError(f"invalid or malformed argument: '{variable_params}'")
no_log = self._task.no_log
tempvars = {}
if self._task.delegate_to:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
cvars = variables.get('ansible_delegated_vars', {}).get(self._task.delegate_to, {})
else:
cvars = variables
templar.available_variables = cvars
if cvars.get('ansible_connection') is not None:
current_connection = templar.template(cvars['ansible_connection'])
else:
current_connection = self._task.connection
if (not self._connection or
not getattr(self._connection, 'connected', False) or
not self._connection.matches_name([current_connection]) or
self._play_context.remote_addr != self._connection._play_context.remote_addr):
self._connection = self._get_connection(cvars, templar, current_connection)
else:
self._connection._play_context = self._play_context
self._set_become_plugin(cvars, templar, self._connection)
plugin_vars = self._set_connection_options(cvars, templar)
vars_copy = variables.copy()
self._connection.update_vars(vars_copy)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
templar.available_variables = vars_copy
self._connection._play_context = self._play_context.set_task_and_variable_override(task=self._task, variables=vars_copy, templar=templar)
if 'ansible_python_interpreter' not in cvars and 'ansible_network_os' in cvars and getattr(self._connection, '_remote_is_local', False):
cvars['ansible_python_interpreter'] = sys.executable
self._handler, module_context = self._get_action_handler_with_module_context(templar=templar)
if module_context is not None:
module_defaults_fqcn = module_context.resolved_fqcn
else:
module_defaults_fqcn = self._task.resolved_action
self._task.args = get_action_args_with_defaults(
module_defaults_fqcn, self._task.args, self._task.module_defaults, templar,
action_groups=self._task._parent._play._action_groups
)
omit_token = variables.get('omit')
if omit_token is not None:
self._task.args = remove_omit(self._task.args, omit_token)
retries = 1
if self._task.retries is not None:
retries += max(0, self._task.retries)
elif self._task.until:
retries += 3
delay = self._task.delay
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
if delay < 0:
delay = 1
display.debug("starting attempt loop")
result = None
for attempt in range(1, retries + 1):
display.debug("running the handler")
try:
if self._task.timeout:
old_sig = signal.signal(signal.SIGALRM, task_timeout)
signal.alarm(self._task.timeout)
result = self._handler.run(task_vars=vars_copy)
except (AnsibleActionFail, AnsibleActionSkip) as e:
return e.result
except AnsibleConnectionFailure as e:
return dict(unreachable=True, msg=to_text(e))
except TaskTimeoutError as e:
msg = 'The %s action failed to execute in the expected time frame (%d) and was terminated' % (self._task.action, self._task.timeout)
return dict(failed=True, msg=msg)
finally:
if self._task.timeout:
signal.alarm(0)
old_sig = signal.signal(signal.SIGALRM, old_sig)
self._handler.cleanup()
display.debug("handler run complete")
result["_ansible_no_log"] = no_log
if self._task.action not in C._ACTION_WITH_CLEAN_FACTS:
result = wrap_var(result)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
if self._task.register:
if not isidentifier(self._task.register):
raise AnsibleError("Invalid variable name in 'register' specified: '%s'" % self._task.register)
vars_copy[self._task.register] = result
if self._task.async_val > 0:
if self._task.poll > 0 and not result.get('skipped') and not result.get('failed'):
result = self._poll_async_result(result=result, templar=templar, task_vars=vars_copy)
if result.get('failed'):
self._final_q.send_callback(
'v2_runner_on_async_failed',
TaskResult(self._host.name,
self._task._uuid,
result,
task_fields=self._task.dump_attrs()))
else:
self._final_q.send_callback(
'v2_runner_on_async_ok',
TaskResult(self._host.name,
self._task._uuid,
result,
task_fields=self._task.dump_attrs()))
result["_ansible_no_log"] = no_log
def _evaluate_changed_when_result(result):
if self._task.changed_when is not None and self._task.changed_when:
cond = Conditional(loader=self._loader)
cond.when = self._task.changed_when
result['changed'] = cond.evaluate_conditional(templar, vars_copy)
def _evaluate_failed_when_result(result):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
if self._task.failed_when:
cond = Conditional(loader=self._loader)
cond.when = self._task.failed_when
failed_when_result = cond.evaluate_conditional(templar, vars_copy)
result['failed_when_result'] = result['failed'] = failed_when_result
else:
failed_when_result = False
return failed_when_result
if 'ansible_facts' in result and self._task.action not in C._ACTION_DEBUG:
if self._task.action in C._ACTION_WITH_CLEAN_FACTS:
if self._task.delegate_to and self._task.delegate_facts:
if '_ansible_delegated_vars' in vars_copy:
vars_copy['_ansible_delegated_vars'].update(result['ansible_facts'])
else:
vars_copy['_ansible_delegated_vars'] = result['ansible_facts']
else:
vars_copy.update(result['ansible_facts'])
else:
af = wrap_var(result['ansible_facts'])
vars_copy['ansible_facts'] = combine_vars(vars_copy.get('ansible_facts', {}), namespace_facts(af))
if C.INJECT_FACTS_AS_VARS:
vars_copy.update(clean_facts(af))
if 'failed' not in result:
if 'rc' in result and result['rc'] not in [0, "0"]:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
result['failed'] = True
else:
result['failed'] = False
if retries > 1:
result['attempts'] = attempt
if 'changed' not in result:
result['changed'] = False
if self._task.action not in C._ACTION_WITH_CLEAN_FACTS:
result = wrap_var(result)
if self._task.register:
vars_copy[self._task.register] = result
if 'skipped' not in result:
condname = 'changed'
try:
_evaluate_changed_when_result(result)
condname = 'failed'
_evaluate_failed_when_result(result)
except AnsibleError as e:
result['failed'] = True
result['%s_when_result' % condname] = to_text(e)
if retries > 1:
cond = Conditional(loader=self._loader)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
cond.when = self._task.until or [not result['failed']]
if cond.evaluate_conditional(templar, vars_copy):
break
else:
if attempt < retries:
result['_ansible_retry'] = True
result['retries'] = retries
display.debug('Retrying task, attempt %d of %d' % (attempt, retries))
self._final_q.send_callback(
'v2_runner_retry',
TaskResult(
self._host.name,
self._task._uuid,
result,
task_fields=self._task.dump_attrs()
)
)
time.sleep(delay)
self._handler = self._get_action_handler(templar=templar)
else:
if retries > 1:
result['attempts'] = retries - 1
result['failed'] = True
if self._task.action not in C._ACTION_WITH_CLEAN_FACTS:
result = wrap_var(result)
if self._task.register:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
variables[self._task.register] = result
if 'ansible_facts' in result and self._task.action not in C._ACTION_DEBUG:
if self._task.action in C._ACTION_WITH_CLEAN_FACTS:
variables.update(result['ansible_facts'])
else:
af = wrap_var(result['ansible_facts'])
variables['ansible_facts'] = combine_vars(variables.get('ansible_facts', {}), namespace_facts(af))
if C.INJECT_FACTS_AS_VARS:
variables.update(clean_facts(af))
if self._task.notify is not None:
result['_ansible_notify'] = self._task.notify
if self._task.delegate_to:
result["_ansible_delegated_vars"] = {'ansible_delegated_host': self._task.delegate_to}
for k in plugin_vars:
result["_ansible_delegated_vars"][k] = cvars.get(k)
for requireshed in ('ansible_host', 'ansible_port', 'ansible_user', 'ansible_connection'):
if requireshed not in result["_ansible_delegated_vars"] and requireshed in cvars:
result["_ansible_delegated_vars"][requireshed] = cvars.get(requireshed)
display.debug("attempt loop complete, returning result")
return result
def _poll_async_result(self, result, templar, task_vars=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
'''
Polls for the specified JID to be complete
'''
if task_vars is None:
task_vars = self._job_vars
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
async_jid = result.get('ansible_job_id')
if async_jid is None:
return dict(failed=True, msg="No job id was returned by the async task")
async_task = Task.load(dict(action='async_status', args={'jid': async_jid}, environment=self._task.environment))
async_handler = self._shared_loader_obj.action_loader.get(
'ansible.legacy.async_status',
task=async_task,
connection=self._connection,
play_context=self._play_context,
loader=self._loader,
templar=templar,
shared_loader_obj=self._shared_loader_obj,
)
time_left = self._task.async_val
while time_left > 0:
time.sleep(self._task.poll)
try:
async_result = async_handler.run(task_vars=task_vars)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
if (int(async_result.get('finished', 0)) == 1 or
('failed' in async_result and async_result.get('_ansible_parsed', False)) or
'skipped' in async_result):
break
except Exception as e:
display.vvvv("Exception during async poll, retrying... (%s)" % to_text(e))
display.debug("Async poll exception was:\n%s" % to_text(traceback.format_exc()))
try:
async_handler._connection.reset()
except AttributeError:
pass
time_left -= self._task.poll
if time_left <= 0:
raise
else:
time_left -= self._task.poll
self._final_q.send_callback(
'v2_runner_on_async_poll',
TaskResult(
self._host.name,
async_task._uuid,
async_result,
task_fields=async_task.dump_attrs(),
),
)
if int(async_result.get('finished', 0)) != 1:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
if async_result.get('_ansible_parsed'):
return dict(failed=True, msg="async task did not complete within the requested time - %ss" % self._task.async_val, async_result=async_result)
else:
return dict(failed=True, msg="async task produced unparseable results", async_result=async_result)
else:
cleanup_task = Task.load(
{
'async_status': {
'jid': async_jid,
'mode': 'cleanup',
},
'environment': self._task.environment,
}
)
cleanup_handler = self._shared_loader_obj.action_loader.get(
'ansible.legacy.async_status',
task=cleanup_task,
connection=self._connection,
play_context=self._play_context,
loader=self._loader,
templar=templar,
shared_loader_obj=self._shared_loader_obj,
)
cleanup_handler.run(task_vars=task_vars)
cleanup_handler.cleanup(force=True)
async_handler.cleanup(force=True)
return async_result
def _get_become(self, name):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
become = become_loader.get(name)
if not become:
raise AnsibleError("Invalid become method specified, could not find matching plugin: '%s'. "
"Use `ansible-doc -t become -l` to list available plugins." % name)
return become
def _get_connection(self, cvars, templar, current_connection):
'''
Reads the connection property for the host, and returns the
correct connection object from the list of connection plugins
'''
self._play_context.connection = current_connection
conn_type = self._play_context.connection
connection, plugin_load_context = self._shared_loader_obj.connection_loader.get_with_context(
conn_type,
self._play_context,
self._new_stdin,
task_uuid=self._task._uuid,
ansible_playbook_pid=to_text(os.getppid())
)
if not connection:
raise AnsibleError("the connection plugin '%s' was not found" % conn_type)
self._set_become_plugin(cvars, templar, connection)
self._play_context.set_attributes_from_plugin(connection)
return connection
def _set_become_plugin(self, cvars, templar, connection):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
if cvars.get('ansible_become') is not None:
become = boolean(templar.template(cvars['ansible_become']))
else:
become = self._task.become
if become:
if cvars.get('ansible_become_method'):
become_plugin = self._get_become(templar.template(cvars['ansible_become_method']))
else:
become_plugin = self._get_become(self._task.become_method)
else:
become_plugin = None
try:
connection.set_become_plugin(become_plugin)
except AttributeError:
pass
if become_plugin:
if getattr(connection.become, 'require_tty', False) and not getattr(connection, 'has_tty', False):
raise AnsibleError(
"The '%s' connection does not provide a TTY which is required for the selected "
"become plugin: %s." % (connection._load_name, become_plugin.name)
)
self._play_context.set_become_plugin(become_plugin.name)
def _set_plugin_options(self, plugin_type, variables, templar, task_keys):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
try:
plugin = getattr(self._connection, '_%s' % plugin_type)
except AttributeError:
plugin = getattr(self._connection, plugin_type)
if plugin_type == "ssh_type_conn":
plugin_type = "connection"
option_vars = C.config.get_plugin_vars(plugin_type, plugin._load_name)
options = {}
for k in option_vars:
if k in variables:
options[k] = templar.template(variables[k])
plugin.set_options(task_keys=task_keys, var_options=options)
return option_vars
def _set_connection_options(self, variables, templar):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
varnames = []
option_vars = C.config.get_plugin_vars('connection', self._connection._load_name)
varnames.extend(option_vars)
options = {'_extras': {}}
for k in option_vars:
if k in variables:
options[k] = templar.template(variables[k])
if getattr(self._connection, 'allow_extras', False):
for k in variables:
if k.startswith('ansible_%s_' % self._connection._load_name) and k not in options:
options['_extras'][k] = templar.template(variables[k])
task_keys = self._task.dump_attrs()
task_keys['timeout'] = self._play_context.timeout
if self._play_context.password:
task_keys['password'] = self._play_context.password
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
del task_keys['retries']
self._connection.set_options(task_keys=task_keys, var_options=options)
varnames.extend(self._set_plugin_options('shell', variables, templar, task_keys))
if self._connection.become is not None:
if self._play_context.become_pass:
task_keys['become_pass'] = self._play_context.become_pass
varnames.extend(self._set_plugin_options('become', variables, templar, task_keys))
for option in ('become_user', 'become_flags', 'become_exe', 'become_pass'):
try:
setattr(self._play_context, option, self._connection.become.get_option(option))
except KeyError:
pass
self._play_context.prompt = self._connection.become.prompt
sub = getattr(self._connection, '_sub_plugin', None)
if sub is not None and sub.get('type') != 'external':
plugin_type = get_plugin_class(sub.get("obj"))
varnames.extend(self._set_plugin_options(plugin_type, variables, templar, task_keys))
sub_conn = getattr(self._connection, 'ssh_type_conn', None)
if sub_conn is not None:
varnames.extend(self._set_plugin_options("ssh_type_conn", variables, templar, task_keys))
return varnames
def _get_action_handler(self, templar):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
'''
Returns the correct action plugin to handle the requestion task action
'''
return self._get_action_handler_with_module_context(templar)[0]
def _get_action_handler_with_module_context(self, templar):
'''
Returns the correct action plugin to handle the requestion task action and the module context
'''
module_collection, separator, module_name = self._task.action.rpartition(".")
module_prefix = module_name.split('_')[0]
if module_collection:
network_action = "{0}.{1}".format(module_collection, module_prefix)
else:
network_action = module_prefix
collections = self._task.collections
module = self._shared_loader_obj.module_loader.find_plugin_with_context(
self._task.action, collection_list=collections
)
if not module.resolved or not module.action_plugin:
module = None
if module is not None:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
handler_name = module.action_plugin
elif self._shared_loader_obj.action_loader.has_plugin(self._task.action, collection_list=collections):
handler_name = self._task.action
elif all((module_prefix in C.NETWORK_GROUP_MODULES, self._shared_loader_obj.action_loader.has_plugin(network_action, collection_list=collections))):
handler_name = network_action
display.vvvv("Using network group action {handler} for {action}".format(handler=handler_name,
action=self._task.action),
host=self._play_context.remote_addr)
else:
handler_name = 'ansible.legacy.normal'
collections = None
if any(((self._connection.supports_persistence and C.USE_PERSISTENT_CONNECTIONS), self._connection.force_persistence)):
handler_class = self._shared_loader_obj.action_loader.get(handler_name, class_only=True)
if getattr(handler_class, '_requires_connection', True):
self._play_context.timeout = self._connection.get_option('persistent_command_timeout')
display.vvvv('attempting to start connection', host=self._play_context.remote_addr)
display.vvvv('using connection plugin %s' % self._connection.transport, host=self._play_context.remote_addr)
options = self._connection.get_options()
socket_path = start_connection(self._play_context, options, self._task._uuid)
display.vvvv('local domain socket path is %s' % socket_path, host=self._play_context.remote_addr)
setattr(self._connection, '_socket_path', socket_path)
else:
self._connection = self._get_connection({}, templar, 'local')
handler = self._shared_loader_obj.action_loader.get(
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
handler_name,
task=self._task,
connection=self._connection,
play_context=self._play_context,
loader=self._loader,
templar=templar,
shared_loader_obj=self._shared_loader_obj,
collection_list=collections
)
if not handler:
raise AnsibleError("the handler '%s' was not found" % handler_name)
return handler, module
def start_connection(play_context, options, task_uuid):
'''
Starts the persistent connection
'''
candidate_paths = [C.ANSIBLE_CONNECTION_PATH or os.path.dirname(sys.argv[0])]
candidate_paths.extend(os.environ.get('PATH', '').split(os.pathsep))
for dirname in candidate_paths:
ansible_connection = os.path.join(dirname, 'ansible-connection')
if os.path.isfile(ansible_connection):
display.vvvv("Found ansible-connection at path {0}".format(ansible_connection))
break
else:
raise AnsibleError("Unable to find location of 'ansible-connection'. "
"Please set or check the value of ANSIBLE_CONNECTION_PATH")
env = os.environ.copy()
env.update({
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
'ANSIBLE_BECOME_PLUGINS': become_loader.print_paths(),
'ANSIBLE_CLICONF_PLUGINS': cliconf_loader.print_paths(),
'ANSIBLE_COLLECTIONS_PATH': to_native(os.pathsep.join(AnsibleCollectionConfig.collection_paths)),
'ANSIBLE_CONNECTION_PLUGINS': connection_loader.print_paths(),
'ANSIBLE_HTTPAPI_PLUGINS': httpapi_loader.print_paths(),
'ANSIBLE_NETCONF_PLUGINS': netconf_loader.print_paths(),
'ANSIBLE_TERMINAL_PLUGINS': terminal_loader.print_paths(),
})
verbosity = []
if display.verbosity:
verbosity.append('-%s' % ('v' * display.verbosity))
python = sys.executable
master, slave = pty.openpty()
p = subprocess.Popen(
[python, ansible_connection, *verbosity, to_text(os.getppid()), to_text(task_uuid)],
stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env
)
os.close(slave)
old = termios.tcgetattr(master)
new = termios.tcgetattr(master)
new[3] = new[3] & ~termios.ICANON
try:
termios.tcsetattr(master, termios.TCSANOW, new)
write_to_file_descriptor(master, options)
write_to_file_descriptor(master, play_context.serialize())
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/executor/task_executor.py
|
(stdout, stderr) = p.communicate()
finally:
termios.tcsetattr(master, termios.TCSANOW, old)
os.close(master)
if p.returncode == 0:
result = json.loads(to_text(stdout, errors='surrogate_then_replace'))
else:
try:
result = json.loads(to_text(stderr, errors='surrogate_then_replace'))
except json.decoder.JSONDecodeError:
result = {'error': to_text(stderr, errors='surrogate_then_replace')}
if 'messages' in result:
for level, message in result['messages']:
if level == 'log':
display.display(message, log_only=True)
elif level in ('debug', 'v', 'vv', 'vvv', 'vvvv', 'vvvvv', 'vvvvvv'):
getattr(display, level)(message, host=play_context.remote_addr)
else:
if hasattr(display, level):
getattr(display, level)(message)
else:
display.vvvv(message, host=play_context.remote_addr)
if 'error' in result:
if display.verbosity > 2:
if result.get('exception'):
msg = "The full traceback is:\n" + result['exception']
display.display(msg, color=C.COLOR_ERROR)
raise AnsibleError(result['error'])
return result['socket_path']
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
#
#
#
#
from __future__ import annotations
import os
import sys
from collections import defaultdict
from collections.abc import Mapping, MutableMapping, Sequence
from hashlib import sha1
from jinja2.exceptions import UndefinedError
from ansible import constants as C
from ansible.errors import AnsibleError, AnsibleParserError, AnsibleUndefinedVariable, AnsibleFileNotFound, AnsibleAssertionError, AnsibleTemplateError
from ansible.inventory.host import Host
from ansible.inventory.helpers import sort_groups, get_group_vars
from ansible.module_utils.common.text.converters import to_text
from ansible.module_utils.six import text_type, string_types
from ansible.plugins.loader import lookup_loader
from ansible.vars.fact_cache import FactCache
from ansible.template import Templar
from ansible.utils.display import Display
from ansible.utils.listify import listify_lookup_plugin_terms
from ansible.utils.vars import combine_vars, load_extra_vars, load_options_vars
from ansible.utils.unsafe_proxy import wrap_var
from ansible.vars.clean import namespace_facts, clean_facts
from ansible.vars.plugins import get_vars_from_inventory_sources, get_vars_from_path
display = Display()
def preprocess_vars(a):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
'''
Ensures that vars contained in the parameter passed in are
returned as a list of dictionaries, to ensure for instance
that vars loaded from a file conform to an expected state.
'''
if a is None:
return None
elif not isinstance(a, list):
data = [a]
else:
data = a
for item in data:
if not isinstance(item, MutableMapping):
raise AnsibleError("variable files must contain either a dictionary of variables, or a list of dictionaries. Got: %s (%s)" % (a, type(a)))
return data
class VariableManager:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
_ALLOWED = frozenset(['plugins_by_group', 'groups_plugins_play', 'groups_plugins_inventory', 'groups_inventory',
'all_plugins_play', 'all_plugins_inventory', 'all_inventory'])
def __init__(self, loader=None, inventory=None, version_info=None):
self._nonpersistent_fact_cache = defaultdict(dict)
self._vars_cache = defaultdict(dict)
self._extra_vars = defaultdict(dict)
self._host_vars_files = defaultdict(dict)
self._group_vars_files = defaultdict(dict)
self._inventory = inventory
self._loader = loader
self._hostvars = None
self._omit_token = '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest()
self._options_vars = load_options_vars(version_info)
basedir = self._options_vars.get('basedir', False)
self.safe_basedir = bool(basedir is False or basedir)
self._extra_vars = load_extra_vars(loader=self._loader)
try:
self._fact_cache = FactCache()
except AnsibleError as e:
display.warning(to_text(e))
self._fact_cache = {}
def __getstate__(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
data = dict(
fact_cache=self._fact_cache,
np_fact_cache=self._nonpersistent_fact_cache,
vars_cache=self._vars_cache,
extra_vars=self._extra_vars,
host_vars_files=self._host_vars_files,
group_vars_files=self._group_vars_files,
omit_token=self._omit_token,
options_vars=self._options_vars,
inventory=self._inventory,
safe_basedir=self.safe_basedir,
)
return data
def __setstate__(self, data):
self._fact_cache = data.get('fact_cache', defaultdict(dict))
self._nonpersistent_fact_cache = data.get('np_fact_cache', defaultdict(dict))
self._vars_cache = data.get('vars_cache', defaultdict(dict))
self._extra_vars = data.get('extra_vars', dict())
self._host_vars_files = data.get('host_vars_files', defaultdict(dict))
self._group_vars_files = data.get('group_vars_files', defaultdict(dict))
self._omit_token = data.get('omit_token', '__omit_place_holder__%s' % sha1(os.urandom(64)).hexdigest())
self._inventory = data.get('inventory', None)
self._options_vars = data.get('options_vars', dict())
self.safe_basedir = data.get('safe_basedir', False)
self._loader = None
self._hostvars = None
@property
def extra_vars(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
return self._extra_vars
def set_inventory(self, inventory):
self._inventory = inventory
def get_vars(self, play=None, host=None, task=None, include_hostvars=True, include_delegate_to=False, use_cache=True,
_hosts=None, _hosts_all=None, stage='task'):
'''
Returns the variables, with optional "context" given via the parameters
for the play, host, and task (which could possibly result in different
sets of variables being returned due to the additional context).
The order of precedence is:
- play->roles->get_default_vars (if there is a play context)
- group_vars_files[host] (if there is a host context)
- host_vars_files[host] (if there is a host context)
- host->get_vars (if there is a host context)
- fact_cache[host] (if there is a host context)
- play vars (if there is a play context)
- play vars_files (if there's no host context, ignore
file names that cannot be templated)
- task->get_vars (if there is a task context)
- vars_cache[host] (if there is a host context)
- extra vars
``_hosts`` and ``_hosts_all`` should be considered private args, with only internal trusted callers relying
on the functionality they provide. These arguments may be removed at a later date without a deprecation
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
period and without warning.
'''
display.debug("in VariableManager get_vars()")
all_vars = dict()
magic_variables = self._get_magic_variables(
play=play,
host=host,
task=task,
include_hostvars=include_hostvars,
_hosts=_hosts,
_hosts_all=_hosts_all,
)
_vars_sources = {}
def _combine_and_track(data, new_data, source):
'''
Wrapper function to update var sources dict and call combine_vars()
See notes in the VarsWithSources docstring for caveats and limitations of the source tracking
'''
if new_data == {}:
return data
if C.DEFAULT_DEBUG:
for key in new_data:
_vars_sources[key] = source
return combine_vars(data, new_data)
basedirs = []
if self.safe_basedir:
basedirs = [self._loader.get_basedir()]
if play:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
for role in play.get_roles():
role_is_static_or_completed = role.static or role._completed.get(host.name, False)
if role.public and role_is_static_or_completed or \
role.public is None and not C.DEFAULT_PRIVATE_ROLE_VARS and role_is_static_or_completed:
all_vars = _combine_and_track(all_vars, role.get_default_vars(), "role '%s' defaults" % role.name)
if task:
if C.PLAYBOOK_VARS_ROOT == 'all':
basedirs = task.get_search_path()
elif C.PLAYBOOK_VARS_ROOT in ('bottom', 'playbook_dir'):
basedirs = [task.get_search_path()[0]]
elif C.PLAYBOOK_VARS_ROOT != 'top':
raise AnsibleError('Unknown playbook vars logic: %s' % C.PLAYBOOK_VARS_ROOT)
if task._role is not None and (play or task.action in C._ACTION_INCLUDE_ROLE):
all_vars = _combine_and_track(all_vars, task._role.get_default_vars(dep_chain=task.get_dep_chain()),
"role '%s' defaults" % task._role.name)
if host:
all_group = self._inventory.groups.get('all')
host_groups = sort_groups([g for g in host.get_groups() if g.name not in ['all']])
def _get_plugin_vars(plugin, path, entities):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
data = {}
try:
data = plugin.get_vars(self._loader, path, entities)
except AttributeError:
try:
for entity in entities:
if isinstance(entity, Host):
data |= plugin.get_host_vars(entity.name)
else:
data |= plugin.get_group_vars(entity.name)
except AttributeError:
if hasattr(plugin, 'run'):
raise AnsibleError("Cannot use v1 type vars plugin %s from %s" % (plugin._load_name, plugin._original_path))
else:
raise AnsibleError("Invalid vars plugin %s from %s" % (plugin._load_name, plugin._original_path))
return data
def _plugins_inventory(entities):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
''' merges all entities by inventory source '''
return get_vars_from_inventory_sources(self._loader, self._inventory._sources, entities, stage)
def _plugins_play(entities):
''' merges all entities adjacent to play '''
data = {}
for path in basedirs:
data = _combine_and_track(data, get_vars_from_path(self._loader, path, entities, stage), "path '%s'" % path)
return data
def all_inventory():
return all_group.get_vars()
def all_plugins_inventory():
return _plugins_inventory([all_group])
def all_plugins_play():
return _plugins_play([all_group])
def groups_inventory():
''' gets group vars from inventory '''
return get_group_vars(host_groups)
def groups_plugins_inventory():
''' gets plugin sources from inventory for groups '''
return _plugins_inventory(host_groups)
def groups_plugins_play():
''' gets plugin sources from play for groups '''
return _plugins_play(host_groups)
def plugins_by_groups():
'''
merges all plugin sources by group,
This should be used instead, NOT in combination with the other groups_plugins* functions
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
'''
data = {}
for group in host_groups:
data[group] = _combine_and_track(data[group], _plugins_inventory(group), "inventory group_vars for '%s'" % group)
data[group] = _combine_and_track(data[group], _plugins_play(group), "playbook group_vars for '%s'" % group)
return data
for entry in C.VARIABLE_PRECEDENCE:
if entry in self._ALLOWED:
display.debug('Calling %s to load vars for %s' % (entry, host.name))
all_vars = _combine_and_track(all_vars, locals()[entry](), "group vars, precedence entry '%s'" % entry)
else:
display.warning('Ignoring unknown variable precedence entry: %s' % (entry))
all_vars = _combine_and_track(all_vars, host.get_vars(), "host vars for '%s'" % host)
all_vars = _combine_and_track(all_vars, _plugins_inventory([host]), "inventory host_vars for '%s'" % host)
all_vars = _combine_and_track(all_vars, _plugins_play([host]), "playbook host_vars for '%s'" % host)
try:
facts = wrap_var(self._fact_cache.get(host.name, {}))
all_vars |= namespace_facts(facts)
if C.INJECT_FACTS_AS_VARS:
all_vars = _combine_and_track(all_vars, wrap_var(clean_facts(facts)), "facts")
else:
all_vars = _combine_and_track(all_vars, wrap_var({'ansible_local': facts.get('ansible_local', {})}), "facts")
except KeyError:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
pass
if play:
all_vars = _combine_and_track(all_vars, play.get_vars(), "play vars")
vars_files = play.get_vars_files()
try:
for vars_file_item in vars_files:
temp_vars = combine_vars(all_vars, self._extra_vars)
temp_vars = combine_vars(temp_vars, magic_variables)
templar = Templar(loader=self._loader, variables=temp_vars)
vars_file_list = vars_file_item
if not isinstance(vars_file_list, list):
vars_file_list = [vars_file_list]
try:
for vars_file in vars_file_list:
vars_file = templar.template(vars_file)
if not (isinstance(vars_file, Sequence)):
raise AnsibleError(
"Invalid vars_files entry found: %r\n"
"vars_files entries should be either a string type or "
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
"a list of string types after template expansion" % vars_file
)
try:
play_search_stack = play.get_search_path()
found_file = real_file = self._loader.path_dwim_relative_stack(play_search_stack, 'vars', vars_file)
data = preprocess_vars(self._loader.load_from_file(found_file, unsafe=True, cache=False))
if data is not None:
for item in data:
all_vars = _combine_and_track(all_vars, item, "play vars_files from '%s'" % vars_file)
break
except AnsibleFileNotFound:
continue
except AnsibleParserError:
raise
else:
if include_delegate_to and host:
raise AnsibleFileNotFound("vars file %s was not found" % vars_file_item)
except (UndefinedError, AnsibleUndefinedVariable):
if host is not None and self._fact_cache.get(host.name, dict()).get('module_setup') and task is not None:
raise AnsibleUndefinedVariable("an undefined variable was found when attempting to template the vars_files item '%s'"
% vars_file_item, obj=vars_file_item)
else:
display.vvv("skipping vars_file '%s' due to an undefined variable" % vars_file_item)
continue
display.vvv("Read vars_file '%s'" % vars_file_item)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
except TypeError:
raise AnsibleParserError("Error while reading vars files - please supply a list of file names. "
"Got '%s' of type %s" % (vars_files, type(vars_files)))
for role in play.get_roles():
role_is_static_or_completed = role.static or role._completed.get(host.name, False)
if role.public and role_is_static_or_completed or \
role.public is None and not C.DEFAULT_PRIVATE_ROLE_VARS and role_is_static_or_completed:
all_vars = _combine_and_track(all_vars, role.get_vars(include_params=False, only_exports=True), "role '%s' exported vars" % role.name)
if task:
if task._role:
all_vars = _combine_and_track(all_vars, task._role.get_vars(task.get_dep_chain(), include_params=False, only_exports=False),
"role '%s' all vars" % task._role.name)
all_vars = _combine_and_track(all_vars, task.get_vars(), "task vars")
if host:
all_vars = _combine_and_track(all_vars, self._vars_cache.get(host.get_name(), dict()), "include_vars")
all_vars = _combine_and_track(all_vars, self._nonpersistent_fact_cache.get(host.name, dict()), "set_fact")
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
if task:
if task._role:
all_vars = _combine_and_track(all_vars, task._role.get_role_params(task.get_dep_chain()), "role params")
all_vars = _combine_and_track(all_vars, task.get_include_params(), "include params")
all_vars = _combine_and_track(all_vars, self._extra_vars, "extra vars")
all_vars = _combine_and_track(all_vars, magic_variables, "magic vars")
if task:
all_vars['environment'] = task.environment
if task or play:
all_vars['vars'] = all_vars.copy()
if task and host and task.delegate_to is not None and include_delegate_to:
all_vars['ansible_delegated_vars'], all_vars['_ansible_loop_cache'] = self._get_delegated_vars(play, task, all_vars)
display.debug("done with get_vars()")
if C.DEFAULT_DEBUG:
return VarsWithSources.new_vars_with_sources(all_vars, _vars_sources)
else:
return all_vars
def _get_magic_variables(self, play, host, task, include_hostvars, _hosts=None, _hosts_all=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
'''
Returns a dictionary of so-called "magic" variables in Ansible,
which are special variables we set internally for use.
'''
variables = {}
variables['playbook_dir'] = os.path.abspath(self._loader.get_basedir())
variables['ansible_playbook_python'] = sys.executable
variables['ansible_config_file'] = C.CONFIG_FILE
if play:
dependency_role_names = list({d.get_name() for r in play.roles for d in r.get_all_dependencies()})
play_role_names = [r.get_name() for r in play.roles]
variables['ansible_role_names'] = list(set(dependency_role_names + play_role_names))
variables['ansible_play_role_names'] = play_role_names
variables['ansible_dependent_role_names'] = dependency_role_names
variables['role_names'] = variables['ansible_play_role_names']
variables['ansible_play_name'] = play.get_name()
if task:
if task._role:
variables['role_name'] = task._role.get_name(include_role_fqcn=False)
variables['role_path'] = task._role._role_path
variables['role_uuid'] = text_type(task._role._uuid)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
variables['ansible_collection_name'] = task._role._role_collection
variables['ansible_role_name'] = task._role.get_name()
if self._inventory is not None:
variables['groups'] = self._inventory.get_groups_dict()
if play:
templar = Templar(loader=self._loader)
if not play.finalized and templar.is_template(play.hosts):
pattern = 'all'
else:
pattern = play.hosts or 'all'
if not _hosts_all:
_hosts_all = [h.name for h in self._inventory.get_hosts(pattern=pattern, ignore_restrictions=True)]
if not _hosts:
_hosts = [h.name for h in self._inventory.get_hosts()]
variables['ansible_play_hosts_all'] = _hosts_all[:]
variables['ansible_play_hosts'] = [x for x in variables['ansible_play_hosts_all'] if x not in play._removed_hosts]
variables['ansible_play_batch'] = [x for x in _hosts if x not in play._removed_hosts]
variables['play_hosts'] = variables['ansible_play_batch']
variables['omit'] = self._omit_token
for option, option_value in self._options_vars.items():
variables[option] = option_value
if self._hostvars is not None and include_hostvars:
variables['hostvars'] = self._hostvars
return variables
def get_delegated_vars_and_hostname(self, templar, task, variables):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
"""Get the delegated_vars for an individual task invocation, which may be be in the context
of an individual loop iteration.
Not used directly be VariableManager, but used primarily within TaskExecutor
"""
delegated_vars = {}
delegated_host_name = None
if task.delegate_to:
delegated_host_name = templar.template(task.delegate_to, fail_on_undefined=False)
delegated_host = self._inventory.get_host(delegated_host_name)
if delegated_host is None:
for h in self._inventory.get_hosts(ignore_limits=True, ignore_restrictions=True):
if h.address == delegated_host_name:
delegated_host = h
break
else:
delegated_host = Host(name=delegated_host_name)
delegated_vars['ansible_delegated_vars'] = {
delegated_host_name: self.get_vars(
play=task.get_play(),
host=delegated_host,
task=task,
include_delegate_to=False,
include_hostvars=True,
)
}
delegated_vars['ansible_delegated_vars'][delegated_host_name]['inventory_hostname'] = variables.get('inventory_hostname')
return delegated_vars, delegated_host_name
def _get_delegated_vars(self, play, task, existing_variables):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
if not hasattr(task, 'loop'):
return {}, None
display.deprecated(
'Getting delegated variables via get_vars is no longer used, and is handled within the TaskExecutor.',
version='2.18',
)
vars_copy = existing_variables.copy()
vars_copy['ansible_search_path'] = task.get_search_path()
if self._loader.get_basedir() not in vars_copy['ansible_search_path']:
vars_copy['ansible_search_path'].append(self._loader.get_basedir())
templar = Templar(loader=self._loader, variables=vars_copy)
items = []
has_loop = True
if task.loop_with is not None:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
if task.loop_with in lookup_loader:
fail = True
if task.loop_with == 'first_found':
fail = False
try:
loop_terms = listify_lookup_plugin_terms(terms=task.loop, templar=templar, fail_on_undefined=fail, convert_bare=False)
if not fail:
loop_terms = [t for t in loop_terms if not templar.is_template(t)]
mylookup = lookup_loader.get(task.loop_with, loader=self._loader, templar=templar)
for subdir in ['template', 'var', 'file']:
if subdir in task.action:
break
setattr(mylookup, '_subdir', subdir + 's')
items = wrap_var(mylookup.run(terms=loop_terms, variables=vars_copy))
except AnsibleTemplateError:
items = [None]
else:
raise AnsibleError("Failed to find the lookup named '%s' in the available lookup plugins" % task.loop_with)
elif task.loop is not None:
try:
items = templar.template(task.loop)
except AnsibleTemplateError:
items = [None]
else:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
has_loop = False
items = [None]
delegated_host_vars = dict()
item_var = getattr(task.loop_control, 'loop_var', 'item')
cache_items = False
for item in items:
if item is not None:
vars_copy[item_var] = item
templar.available_variables = vars_copy
delegated_host_name = templar.template(task.delegate_to, fail_on_undefined=False)
if delegated_host_name != task.delegate_to:
cache_items = True
if delegated_host_name is None:
raise AnsibleError(message="Undefined delegate_to host for task:", obj=task._ds)
if not isinstance(delegated_host_name, string_types):
raise AnsibleError(message="the field 'delegate_to' has an invalid type (%s), and could not be"
" converted to a string type." % type(delegated_host_name), obj=task._ds)
if delegated_host_name in delegated_host_vars:
continue
delegated_host = None
if self._inventory is not None:
delegated_host = self._inventory.get_host(delegated_host_name)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
if delegated_host is None:
for h in self._inventory.get_hosts(ignore_limits=True, ignore_restrictions=True):
if h.address == delegated_host_name:
delegated_host = h
break
else:
delegated_host = Host(name=delegated_host_name)
else:
delegated_host = Host(name=delegated_host_name)
delegated_host_vars[delegated_host_name] = self.get_vars(
play=play,
host=delegated_host,
task=task,
include_delegate_to=False,
include_hostvars=True,
)
delegated_host_vars[delegated_host_name]['inventory_hostname'] = vars_copy.get('inventory_hostname')
_ansible_loop_cache = None
if has_loop and cache_items:
_ansible_loop_cache = items
return delegated_host_vars, _ansible_loop_cache
def clear_facts(self, hostname):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
'''
Clears the facts for a host
'''
self._fact_cache.pop(hostname, None)
def set_host_facts(self, host, facts):
'''
Sets or updates the given facts for a host in the fact cache.
'''
if not isinstance(facts, Mapping):
raise AnsibleAssertionError("the type of 'facts' to set for host_facts should be a Mapping but is a %s" % type(facts))
try:
host_cache = self._fact_cache[host]
except KeyError:
host_cache = facts
else:
if not isinstance(host_cache, MutableMapping):
raise TypeError('The object retrieved for {0} must be a MutableMapping but was'
' a {1}'.format(host, type(host_cache)))
host_cache |= facts
self._fact_cache[host] = host_cache
def set_nonpersistent_facts(self, host, facts):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
'''
Sets or updates the given facts for a host in the fact cache.
'''
if not isinstance(facts, Mapping):
raise AnsibleAssertionError("the type of 'facts' to set for nonpersistent_facts should be a Mapping but is a %s" % type(facts))
try:
self._nonpersistent_fact_cache[host] |= facts
except KeyError:
self._nonpersistent_fact_cache[host] = facts
def set_host_variable(self, host, varname, value):
'''
Sets a value in the vars_cache for a host.
'''
if host not in self._vars_cache:
self._vars_cache[host] = dict()
if varname in self._vars_cache[host] and isinstance(self._vars_cache[host][varname], MutableMapping) and isinstance(value, MutableMapping):
self._vars_cache[host] = combine_vars(self._vars_cache[host], {varname: value})
else:
self._vars_cache[host][varname] = value
class VarsWithSources(MutableMapping):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
'''
Dict-like class for vars that also provides source information for each var
This class can only store the source for top-level vars. It does no tracking
on its own, just shows a debug message with the information that it is provided
when a particular var is accessed.
'''
def __init__(self, *args, **kwargs):
''' Dict-compatible constructor '''
self.data = dict(*args, **kwargs)
self.sources = {}
@classmethod
def new_vars_with_sources(cls, data, sources):
''' Alternate constructor method to instantiate class with sources '''
v = cls(data)
v.sources = sources
return v
def get_source(self, key):
return self.sources.get(key, None)
def __getitem__(self, key):
val = self.data[key]
display.debug("variable '%s' from source: %s" % (key, self.sources.get(key, "unknown")))
return val
def __setitem__(self, key, value):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 82,264 |
delegate_to: "{{var}}" when: var != "" causes a "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead" error on 2.16
|
### Summary
I have a task to conditionally install an SSH key on another machine:
```yaml
- authorized_key: ...
delegate_to: "{{ jenkins_install_key_on }}"
when: jenkins_install_key_on != ""
```
This works fine when `jenkins_install_key_on` is set to a non-blank value, but fails when `jenkins_install_key_on` is set to an empty string:
```
fatal: [jammy -> {{ jenkins_install_key_on }}]: FAILED! => {"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"}
```
It used to work with ansible-core 2.15 and older.
### Issue Type
Bug Report
### Component Name
delegate_to
### Ansible Version
```console
$ ansible --version
ansible [core 2.16.0]
config file = /home/mg/src/deployments/provisioning/ansible.cfg
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/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
ACTION_WARNINGS(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE_PLUGIN(/home/mg/src/deployments/provisioning/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/mg/src/deployments/provisioning/ansible.cfg) = .cache/facts/
CACHE_PLUGIN_TIMEOUT(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
CALLBACKS_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = ['fancy_html']
CONFIG_FILE() = /home/mg/src/deployments/provisioning/ansible.cfg
DEFAULT_FORKS(/home/mg/src/deployments/provisioning/ansible.cfg) = 15
DEFAULT_GATHERING(/home/mg/src/deployments/provisioning/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/mg/src/deployments/provisioning/ansible.cfg) = ['/home/mg/src/deployments/provisioning/inventory']
DEFAULT_LOG_PATH(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/ansible.log
DEFAULT_REMOTE_USER(/home/mg/src/deployments/provisioning/ansible.cfg) = root
DEFAULT_STDOUT_CALLBACK(/home/mg/src/deployments/provisioning/ansible.cfg) = yaml
DEFAULT_VAULT_PASSWORD_FILE(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/askpas>
EDITOR(env: EDITOR) = vim
INTERPRETER_PYTHON(/home/mg/src/deployments/provisioning/ansible.cfg) = python3
RETRY_FILES_ENABLED(/home/mg/src/deployments/provisioning/ansible.cfg) = False
CACHE:
=====
jsonfile:
________
_timeout(/home/mg/src/deployments/provisioning/ansible.cfg) = 86400
_uri(/home/mg/src/deployments/provisioning/ansible.cfg) = /home/mg/src/deployments/provisioning/.cache/facts
CONNECTION:
==========
paramiko_ssh:
____________
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
ssh:
___
remote_user(/home/mg/src/deployments/provisioning/ansible.cfg) = root
```
### OS / Environment
Ubuntu 23.10
### Steps to Reproduce
<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- hosts: all
gather_facts: no
tasks:
- debug: msg="hello"
delegate_to: "{{ var }}"
when: var != ""
vars:
var: ""
```
### Expected Results
I expect the task to be skipped.
### Actual Results
```console
$ ansible-playbook -i localhost, ansible-delegate-to-blank.yml -vvvv
ansible-playbook [core 2.16.0]
config file = None
configured module search path = ['/home/mg/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/mg/.ansible/collections:/usr/share/ansible/collections
executable location = /home/mg/.local/bin/ansible-playbook
python version = 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] (/home/mg/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.2
libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading callback plugin default of type stdout, v2.0 from /home/mg/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: ansible-delegate-to-blank.yml **************************************************************************************
Positional arguments: ansible-delegate-to-blank.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('localhost,',)
forks: 5
1 plays in ansible-delegate-to-blank.yml
PLAY [all] *******************************************************************************************************************
TASK [debug] *****************************************************************************************************************
task path: /home/mg/tmp/ansible-delegate-to-blank.yml:4
fatal: [localhost -> {{ var }}]: FAILED! => {
"msg": "Supplied entity must be Host or Group, got <class 'ansible.inventory.host.Host'> instead"
}
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 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/82264
|
https://github.com/ansible/ansible/pull/82319
|
3a42a0036875c8cab6a62ab9ea67a365e1dd4781
|
6ebefaceb6cd0d4961776a94d63a71fc1fc28bc0
| 2023-11-22T08:22:01Z |
python
| 2023-12-04T15:19:12Z |
lib/ansible/vars/manager.py
|
self.data[key] = value
def __delitem__(self, key):
del self.data[key]
def __iter__(self):
return iter(self.data)
def __len__(self):
return len(self.data)
def __contains__(self, key):
return self.data.__contains__(key)
def copy(self):
return VarsWithSources.new_vars_with_sources(self.data.copy(), self.sources.copy())
def __or__(self, other):
if isinstance(other, MutableMapping):
c = self.data.copy()
c.update(other)
return c
return NotImplemented
def __ror__(self, other):
if isinstance(other, MutableMapping):
c = self.__class__()
c.update(other)
c.update(self.data)
return c
return NotImplemented
def __ior__(self, other):
self.data.update(other)
return self.data
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
from __future__ import annotations
import json
import sys
_PY_MIN = (3, 7)
if sys.version_info < _PY_MIN:
print(json.dumps(dict(
failed=True,
msg=f"ansible-core requires a minimum of Python version {'.'.join(map(str, _PY_MIN))}. Current version: {''.join(sys.version.splitlines())}",
)))
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
sys.exit(1)
import __main__
import atexit
import errno
import datetime
import grp
import fcntl
import locale
import os
import pwd
import platform
import re
import select
import selectors
import shlex
import shutil
import signal
import stat
import subprocess
import tempfile
import time
import traceback
import types
from itertools import chain, repeat
try:
import syslog
HAS_SYSLOG = True
except ImportError:
HAS_SYSLOG = False
try:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
from systemd import journal, daemon as systemd_daemon
has_journal = hasattr(journal, 'sendv') and systemd_daemon.booted()
except (ImportError, AttributeError):
has_journal = False
HAVE_SELINUX = False
try:
from ansible.module_utils.compat import selinux
HAVE_SELINUX = True
except ImportError:
pass
NoneType = type(None)
from ._text import to_native, to_bytes, to_text
from ansible.module_utils.common.text.converters import (
jsonify,
container_to_bytes as json_dict_unicode_to_bytes,
container_to_text as json_dict_bytes_to_unicode,
)
from ansible.module_utils.common.arg_spec import ModuleArgumentSpecValidator
from ansible.module_utils.common.text.formatters import (
lenient_lowercase,
bytes_to_human,
human_to_bytes,
SIZE_RANGES,
)
import hashlib
def _get_available_hash_algorithms():
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
"""Return a dictionary of available hash function names and their associated function."""
try:
algorithm_names = hashlib.algorithms_available
except AttributeError:
algorithm_names = set(hashlib.algorithms)
algorithms = {}
for algorithm_name in algorithm_names:
algorithm_func = getattr(hashlib, algorithm_name, None)
if algorithm_func:
try:
algorithm_func()
except Exception:
pass
else:
algorithms[algorithm_name] = algorithm_func
return algorithms
AVAILABLE_HASH_ALGORITHMS = _get_available_hash_algorithms()
from ansible.module_utils.six.moves.collections_abc import (
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
KeysView,
Mapping, MutableMapping,
Sequence, MutableSequence,
Set, MutableSet,
)
from ansible.module_utils.common.locale import get_best_parsable_locale
from ansible.module_utils.common.process import get_bin_path
from ansible.module_utils.common.file import (
_PERM_BITS as PERM_BITS,
_EXEC_PERM_BITS as EXEC_PERM_BITS,
_DEFAULT_PERM as DEFAULT_PERM,
is_executable,
format_attributes,
get_flags_from_attributes,
FILE_ATTRIBUTES,
)
from ansible.module_utils.common.sys_info import (
get_distribution,
get_distribution_version,
get_platform_subclass,
)
from ansible.module_utils.common.parameters import (
env_fallback,
remove_values,
sanitize_keys,
DEFAULT_TYPE_VALIDATORS,
PASS_VARS,
PASS_BOOLS,
)
from ansible.module_utils.errors import AnsibleFallbackNotFound, AnsibleValidationErrorMultiple, UnsupportedError
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
from ansible.module_utils.six import (
PY2,
PY3,
b,
binary_type,
integer_types,
iteritems,
string_types,
text_type,
)
from ansible.module_utils.six.moves import map, reduce, shlex_quote
from ansible.module_utils.common.validation import (
check_missing_parameters,
safe_eval,
)
from ansible.module_utils.common._utils import get_all_subclasses as _get_all_subclasses
from ansible.module_utils.parsing.convert_bool import BOOLEANS, BOOLEANS_FALSE, BOOLEANS_TRUE, boolean
from ansible.module_utils.common.warnings import (
deprecate,
get_deprecation_messages,
get_warning_messages,
warn,
)
SEQUENCETYPE = frozenset, KeysView, Sequence
PASSWORD_MATCH = re.compile(r'^(?:.+[-_\s])?pass(?:[-_\s]?(?:word|phrase|wrd|wd)?)(?:[-_\s].+)?$', re.I)
imap = map
try:
unicode
except NameError:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
unicode = text_type
try:
basestring
except NameError:
basestring = string_types
_ANSIBLE_ARGS = None
FILE_COMMON_ARGUMENTS = dict(
mode=dict(type='raw'),
owner=dict(type='str'),
group=dict(type='str'),
seuser=dict(type='str'),
serole=dict(type='str'),
selevel=dict(type='str'),
setype=dict(type='str'),
attributes=dict(type='str', aliases=['attr']),
unsafe_writes=dict(type='bool', default=False, fallback=(env_fallback, ['ANSIBLE_UNSAFE_WRITES'])),
)
PASSWD_ARG_RE = re.compile(r'^[-]{0,2}pass[-]?(word|wd)?')
MODE_OPERATOR_RE = re.compile(r'[+=-]')
USERS_RE = re.compile(r'^[ugo]+$')
PERMS_RE = re.compile(r'^[rwxXstugo]*$')
#
#
def get_platform():
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
'''
**Deprecated** Use :py:func:`platform.system` directly.
:returns: Name of the platform the module is running on in a native string
Returns a native string that labels the platform ("Linux", "Solaris", etc). Currently, this is
the result of calling :py:func:`platform.system`.
'''
return platform.system()
#
#
def load_platform_subclass(cls, *args, **kwargs):
"""**Deprecated**: Use ansible.module_utils.common.sys_info.get_platform_subclass instead"""
platform_cls = get_platform_subclass(cls)
return super(cls, platform_cls).__new__(platform_cls)
def get_all_subclasses(cls):
"""**Deprecated**: Use ansible.module_utils.common._utils.get_all_subclasses instead"""
return list(_get_all_subclasses(cls))
def heuristic_log_sanitize(data, no_log_values=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
''' Remove strings that look like passwords from log messages '''
data = to_native(data)
output = []
begin = len(data)
prev_begin = begin
sep = 1
while sep:
try:
end = data.rindex('@', 0, begin)
except ValueError:
output.insert(0, data[0:begin])
break
sep = None
sep_search_end = end
while not sep:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
try:
begin = data.rindex('://', 0, sep_search_end)
except ValueError:
begin = 0
try:
sep = data.index(':', begin + 3, end)
except ValueError:
if begin == 0:
output.insert(0, data[0:prev_begin])
break
sep_search_end = begin
continue
if sep:
output.insert(0, data[end:prev_begin])
output.insert(0, '********')
output.insert(0, data[begin:sep + 1])
prev_begin = begin
output = ''.join(output)
if no_log_values:
output = remove_values(output, no_log_values)
return output
def _load_params():
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
''' read the modules parameters and store them globally.
This function may be needed for certain very dynamic custom modules which
want to process the parameters that are being handed the module. Since
this is so closely tied to the implementation of modules we cannot
guarantee API stability for it (it may change between versions) however we
will try not to break it gratuitously. It is certainly more future-proof
to call this function and consume its outputs than to implement the logic
inside it as a copy in your own code.
'''
global _ANSIBLE_ARGS
if _ANSIBLE_ARGS is not None:
buffer = _ANSIBLE_ARGS
else:
if len(sys.argv) > 1:
if os.path.isfile(sys.argv[1]):
fd = open(sys.argv[1], 'rb')
buffer = fd.read()
fd.close()
else:
buffer = sys.argv[1]
if PY3:
buffer = buffer.encode('utf-8', errors='surrogateescape')
else:
if PY2:
buffer = sys.stdin.read()
else:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
buffer = sys.stdin.buffer.read()
_ANSIBLE_ARGS = buffer
try:
params = json.loads(buffer.decode('utf-8'))
except ValueError:
print('\n{"msg": "Error: Module unable to decode stdin/parameters as valid JSON. Unable to parse what parameters were passed", "failed": true}')
sys.exit(1)
if PY2:
params = json_dict_unicode_to_bytes(params)
try:
return params['ANSIBLE_MODULE_ARGS']
except KeyError:
print('\n{"msg": "Error: Module unable to locate ANSIBLE_MODULE_ARGS in JSON data from stdin. Unable to figure out what parameters were passed", '
'"failed": true}')
sys.exit(1)
def missing_required_lib(library, reason=None, url=None):
hostname = platform.node()
msg = "Failed to import the required Python library (%s) on %s's Python %s." % (library, hostname, sys.executable)
if reason:
msg += " This is required %s." % reason
if url:
msg += " See %s for more info." % url
msg += (" Please read the module documentation and install it in the appropriate location."
" If the required library is installed, but Ansible is using the wrong Python interpreter,"
" please consult the documentation on ansible_python_interpreter")
return msg
class AnsibleModule(object):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
def __init__(self, argument_spec, bypass_checks=False, no_log=False,
mutually_exclusive=None, required_together=None,
required_one_of=None, add_file_common_args=False,
supports_check_mode=False, required_if=None, required_by=None):
'''
Common code for quickly building an ansible module in Python
(although you can write modules with anything that can return JSON).
See :ref:`developing_modules_general` for a general introduction
and :ref:`developing_program_flow_modules` for more detailed explanation.
'''
self._name = os.path.basename(__file__)
self.argument_spec = argument_spec
self.supports_check_mode = supports_check_mode
self.check_mode = False
self.bypass_checks = bypass_checks
self.no_log = no_log
self.mutually_exclusive = mutually_exclusive
self.required_together = required_together
self.required_one_of = required_one_of
self.required_if = required_if
self.required_by = required_by
self.cleanup_files = []
self._debug = False
self._diff = False
self._socket_path = None
self._shell = None
self._syslog_facility = 'LOG_USER'
self._verbosity = 0
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
self.run_command_environ_update = {}
self._clean = {}
self._string_conversion_action = ''
self.aliases = {}
self._legal_inputs = []
self._options_context = list()
self._tmpdir = None
if add_file_common_args:
for k, v in FILE_COMMON_ARGUMENTS.items():
if k not in self.argument_spec:
self.argument_spec[k] = v
self.no_log_values = set()
self._check_locale()
self._load_params()
self._set_internal_properties()
self.validator = ModuleArgumentSpecValidator(self.argument_spec,
self.mutually_exclusive,
self.required_together,
self.required_one_of,
self.required_if,
self.required_by,
)
self.validation_result = self.validator.validate(self.params)
self.params.update(self.validation_result.validated_parameters)
self.no_log_values.update(self.validation_result._no_log_values)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
self.aliases.update(self.validation_result._aliases)
try:
error = self.validation_result.errors[0]
if isinstance(error, UnsupportedError) and self._ignore_unknown_opts:
error = None
except IndexError:
error = None
if error:
msg = self.validation_result.errors.msg
if isinstance(error, UnsupportedError):
msg = "Unsupported parameters for ({name}) {kind}: {msg}".format(name=self._name, kind='module', msg=msg)
self.fail_json(msg=msg)
if self.check_mode and not self.supports_check_mode:
self.exit_json(skipped=True, msg="remote module (%s) does not support check mode" % self._name)
self._CHECK_ARGUMENT_TYPES_DISPATCHER = DEFAULT_TYPE_VALIDATORS
if not self.no_log:
self._log_invocation()
self._selinux_enabled = None
self._selinux_mls_enabled = None
self._selinux_initial_context = None
self._set_cwd()
@property
def tmpdir(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
if self._tmpdir is None:
basedir = None
if self._remote_tmp is not None:
basedir = os.path.expanduser(os.path.expandvars(self._remote_tmp))
if basedir is not None and not os.path.exists(basedir):
try:
os.makedirs(basedir, mode=0o700)
except (OSError, IOError) as e:
self.warn("Unable to use %s as temporary directory, "
"failing back to system: %s" % (basedir, to_native(e)))
basedir = None
else:
self.warn("Module remote_tmp %s did not exist and was "
"created with a mode of 0700, this may cause"
" issues when running as another user. To "
"avoid this, create the remote_tmp dir with "
"the correct permissions manually" % basedir)
basefile = "ansible-moduletmp-%s-" % time.time()
try:
tmpdir = tempfile.mkdtemp(prefix=basefile, dir=basedir)
except (OSError, IOError) as e:
self.fail_json(
msg="Failed to create remote module tmp path at dir %s "
"with prefix %s: %s" % (basedir, basefile, to_native(e))
)
if not self._keep_remote_files:
atexit.register(shutil.rmtree, tmpdir)
self._tmpdir = tmpdir
return self._tmpdir
def warn(self, warning):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
warn(warning)
self.log('[WARNING] %s' % warning)
def deprecate(self, msg, version=None, date=None, collection_name=None):
if version is not None and date is not None:
raise AssertionError("implementation error -- version and date must not both be set")
deprecate(msg, version=version, date=date, collection_name=collection_name)
if date is not None:
self.log('[DEPRECATION WARNING] %s %s' % (msg, date))
else:
self.log('[DEPRECATION WARNING] %s %s' % (msg, version))
def load_file_common_arguments(self, params, path=None):
'''
many modules deal with files, this encapsulates common
options that the file module accepts such that it is directly
available to all modules and they can share code.
Allows to overwrite the path/dest module argument by providing path.
'''
if path is None:
path = params.get('path', params.get('dest', None))
if path is None:
return {}
else:
path = os.path.expanduser(os.path.expandvars(path))
b_path = to_bytes(path, errors='surrogate_or_strict')
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
if params.get('follow', False) and os.path.islink(b_path):
b_path = os.path.realpath(b_path)
path = to_native(b_path)
mode = params.get('mode', None)
owner = params.get('owner', None)
group = params.get('group', None)
seuser = params.get('seuser', None)
serole = params.get('serole', None)
setype = params.get('setype', None)
selevel = params.get('selevel', None)
secontext = [seuser, serole, setype]
if self.selinux_mls_enabled():
secontext.append(selevel)
default_secontext = self.selinux_default_context(path)
for i in range(len(default_secontext)):
if i is not None and secontext[i] == '_default':
secontext[i] = default_secontext[i]
attributes = params.get('attributes', None)
return dict(
path=path, mode=mode, owner=owner, group=group,
seuser=seuser, serole=serole, setype=setype,
selevel=selevel, secontext=secontext, attributes=attributes,
)
def selinux_mls_enabled(self):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
if self._selinux_mls_enabled is None:
self._selinux_mls_enabled = HAVE_SELINUX and selinux.is_selinux_mls_enabled() == 1
return self._selinux_mls_enabled
def selinux_enabled(self):
if self._selinux_enabled is None:
self._selinux_enabled = HAVE_SELINUX and selinux.is_selinux_enabled() == 1
return self._selinux_enabled
def selinux_initial_context(self):
if self._selinux_initial_context is None:
self._selinux_initial_context = [None, None, None]
if self.selinux_mls_enabled():
self._selinux_initial_context.append(None)
return self._selinux_initial_context
def selinux_default_context(self, path, mode=0):
context = self.selinux_initial_context()
if not self.selinux_enabled():
return context
try:
ret = selinux.matchpathcon(to_native(path, errors='surrogate_or_strict'), mode)
except OSError:
return context
if ret[0] == -1:
return context
context = ret[1].split(':', 3)
return context
def selinux_context(self, path):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
context = self.selinux_initial_context()
if not self.selinux_enabled():
return context
try:
ret = selinux.lgetfilecon_raw(to_native(path, errors='surrogate_or_strict'))
except OSError as e:
if e.errno == errno.ENOENT:
self.fail_json(path=path, msg='path %s does not exist' % path)
else:
self.fail_json(path=path, msg='failed to retrieve selinux context')
if ret[0] == -1:
return context
context = ret[1].split(':', 3)
return context
def user_and_group(self, path, expand=True):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
b_path = to_bytes(path, errors='surrogate_or_strict')
if expand:
b_path = os.path.expanduser(os.path.expandvars(b_path))
st = os.lstat(b_path)
uid = st.st_uid
gid = st.st_gid
return (uid, gid)
def find_mount_point(self, path):
'''
Takes a path and returns its mount point
:param path: a string type with a filesystem path
:returns: the path to the mount point as a text type
'''
b_path = os.path.realpath(to_bytes(os.path.expanduser(os.path.expandvars(path)), errors='surrogate_or_strict'))
while not os.path.ismount(b_path):
b_path = os.path.dirname(b_path)
return to_text(b_path, errors='surrogate_or_strict')
def is_special_selinux_path(self, path):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
"""
Returns a tuple containing (True, selinux_context) if the given path is on a
NFS or other 'special' fs mount point, otherwise the return will be (False, None).
"""
try:
f = open('/proc/mounts', 'r')
mount_data = f.readlines()
f.close()
except Exception:
return (False, None)
path_mount_point = self.find_mount_point(path)
for line in mount_data:
(device, mount_point, fstype, options, rest) = line.split(' ', 4)
if to_bytes(path_mount_point) == to_bytes(mount_point):
for fs in self._selinux_special_fs:
if fs in fstype:
special_context = self.selinux_context(path_mount_point)
return (True, special_context)
return (False, None)
def set_default_selinux_context(self, path, changed):
if not self.selinux_enabled():
return changed
context = self.selinux_default_context(path)
return self.set_context_if_different(path, context, False)
def set_context_if_different(self, path, context, changed, diff=None):
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
if not self.selinux_enabled():
return changed
if self.check_file_absent_if_check_mode(path):
return True
cur_context = self.selinux_context(path)
new_context = list(cur_context)
(is_special_se, sp_context) = self.is_special_selinux_path(path)
if is_special_se:
new_context = sp_context
else:
for i in range(len(cur_context)):
if len(context) > i:
if context[i] is not None and context[i] != cur_context[i]:
new_context[i] = context[i]
elif context[i] is None:
new_context[i] = cur_context[i]
if cur_context != new_context:
if diff is not None:
if 'before' not in diff:
diff['before'] = {}
diff['before']['secontext'] = cur_context
if 'after' not in diff:
diff['after'] = {}
diff['after']['secontext'] = new_context
try:
if self.check_mode:
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
return True
rc = selinux.lsetfilecon(to_native(path), ':'.join(new_context))
except OSError as e:
self.fail_json(path=path, msg='invalid selinux context: %s' % to_native(e),
new_context=new_context, cur_context=cur_context, input_was=context)
if rc != 0:
self.fail_json(path=path, msg='set selinux context failed')
changed = True
return changed
def set_owner_if_different(self, path, owner, changed, diff=None, expand=True):
if owner is None:
return changed
b_path = to_bytes(path, errors='surrogate_or_strict')
if expand:
b_path = os.path.expanduser(os.path.expandvars(b_path))
if self.check_file_absent_if_check_mode(b_path):
return True
orig_uid, orig_gid = self.user_and_group(b_path, expand)
try:
uid = int(owner)
except ValueError:
try:
uid = pwd.getpwnam(owner).pw_uid
except KeyError:
path = to_text(b_path)
self.fail_json(path=path, msg='chown failed: failed to look up user %s' % owner)
if orig_uid != uid:
if diff is not None:
if 'before' not in diff:
diff['before'] = {}
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
diff['before']['owner'] = orig_uid
if 'after' not in diff:
diff['after'] = {}
diff['after']['owner'] = uid
if self.check_mode:
return True
try:
os.lchown(b_path, uid, -1)
except (IOError, OSError) as e:
path = to_text(b_path)
self.fail_json(path=path, msg='chown failed: %s' % (to_text(e)))
changed = True
return changed
def set_group_if_different(self, path, group, changed, diff=None, expand=True):
if group is None:
return changed
b_path = to_bytes(path, errors='surrogate_or_strict')
if expand:
b_path = os.path.expanduser(os.path.expandvars(b_path))
if self.check_file_absent_if_check_mode(b_path):
return True
orig_uid, orig_gid = self.user_and_group(b_path, expand)
try:
gid = int(group)
except ValueError:
try:
gid = grp.getgrnam(group).gr_gid
except KeyError:
path = to_text(b_path)
self.fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group)
|
closed
|
ansible/ansible
|
https://github.com/ansible/ansible
| 76,727 |
lineinfile: Fails when creating a backup of Ubuntu 21.10's /etc/resolv.conf (symlink to "../run/systemd/resolve/stub-resolv.conf")
|
### Summary
https://github.com/ansible/ansible/issues/31982 is back.
### Issue Type
Bug Report
### Component Name
lineinfile
### Ansible Version
```console
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
```
### Configuration
```console
$ ansible-config dump --only-changed
$
```
### OS / Environment
Ubuntu 21.10 Server in a VirtualBox, on server and clients, nothing special
### Steps to Reproduce
```
- name: "Check DNS configuration: Remove search list"
ansible.builtin.lineinfile:
backup: "yes"
path: "/etc/resolv.conf"
line: "search x.tld"
state: "absent"
- name: "Check DNS configuration: Cache servers present"
ansible.builtin.lineinfile:
backup: "yes"
line: "{{ item }}"
path: "/etc/resolv.conf"
state: "present"
with_items:
- "nameserver x.x.x.x"
- "nameserver y.y.y.y"
```
### Expected Results
The file is modified, a backup is created.
### Actual Results
```console
<x.x.x.x> (1, b'\r\n{"path": "/etc/resolv.conf.2410.2022-01-11@10:36:56~", "details": "Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n", "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_ansible.builtin.lineinfile_payload_pvwbc704/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py\\", line 1256, in set_attributes_if_different\\n raise Exception(\\"Error while setting attributes: %s\\" % (out + err))\\nException: Error while setting attributes: /etc/resolv.conf.2410.2022-01-11@10:36:56~: Operation not supported\\n\\n", "failed": true, "msg": "chattr failed", "uid": 101, "gid": 103, "owner": "systemd-resolve", "group": "systemd-resolve", "mode": "0644", "state": "file", "size": 920, "invocation": {"module_args": {"backup": true, "line": "nameserver x.x.x.x", "path": "/etc/resolv.conf", "state": "present", "backrefs": false, "create": false, "firstmatch": false, "unsafe_writes": false, "regexp": null, "insertafter": null, "insertbefore": null, "validate": null, "mode": null, "owner": null, "group": null, "seuser": null, "serole": null, "selevel": null, "setype": null, "attributes": null}}}\r\n', b'Shared connection to x.x.x.x closed.\r\n')
<x.x.x.x> Failed to connect to the host via ssh: Shared connection to x.x.x.x closed.
<x.x.x.x> ESTABLISH SSH CONNECTION FOR USER: root
<x.x.x.x> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/4c20d84404 x.x.x.x '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1641897416.2652106-3817-66846454678877/ > /dev/null 2>&1 && sleep 0'"'"''
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ansible.builtin.lineinfile_payload_bccsus14/ansible_ansible.builtin.lineinfile_payload.zip/ansible/module_utils/basic.py", line 1256, in set_attributes_if_different
raise Exception("Error while setting attributes: %s" % (out + err))
Exception: Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported
failed: [x.x.x.x] (item=nameserver x.x.x.x) => {
"ansible_loop_var": "item",
"changed": false,
"details": "Error while setting attributes: /etc/resolv.conf.2577.2022-01-11@10:36:56~: Operation not supported\n",
"gid": 103,
"group": "systemd-resolve",
"invocation": {
"module_args": {
"attributes": null,
"backrefs": false,
"backup": true,
"create": false,
"firstmatch": false,
"group": null,
"insertafter": null,
"insertbefore": null,
"line": "nameserver x.x.x.x",
"mode": null,
"owner": null,
"path": "/etc/resolv.conf",
"regexp": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"state": "present",
"unsafe_writes": false,
"validate": null
}
},
"item": "nameserver x.x.x.x",
"mode": "0644",
"msg": "chattr failed",
"owner": "systemd-resolve",
"path": "/etc/resolv.conf.2577.2022-01-11@10:36:56~",
"size": 946,
"state": "file",
"uid": 101
}
```
### Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
|
https://github.com/ansible/ansible/issues/76727
|
https://github.com/ansible/ansible/pull/78707
|
dd0138ba2127eac0e809d68e00ae117df56db77e
|
9b002d2e63ec0d39c7c3025dfd4be7489c82016b
| 2022-01-11T11:07:14Z |
python
| 2023-12-06T17:02:51Z |
lib/ansible/module_utils/basic.py
|
if orig_gid != gid:
if diff is not None:
if 'before' not in diff:
diff['before'] = {}
diff['before']['group'] = orig_gid
if 'after' not in diff:
diff['after'] = {}
diff['after']['group'] = gid
if self.check_mode:
return True
try:
os.lchown(b_path, -1, gid)
except OSError:
path = to_text(b_path)
self.fail_json(path=path, msg='chgrp failed')
changed = True
return changed
def set_mode_if_different(self, path, mode, changed, diff=None, expand=True):
if mode is None:
return changed
b_path = to_bytes(path, errors='surrogate_or_strict')
if expand:
b_path = os.path.expanduser(os.path.expandvars(b_path))
if self.check_file_absent_if_check_mode(b_path):
return True
path_stat = os.lstat(b_path)
if not isinstance(mode, int):
try:
mode = int(mode, 8)
except Exception:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.