[stable-2.14] Ensure that we do not squash keywords in validate (#79049) (#79062)

* [stable-2.14] Ensure that we do not squash keywords in validate (#79049)

* Ensure that we do not squash keywords in validate. Fixes #79021

* become_user: nobody should only apply to the test tasks, not the setup_test_user role

* Update how become_user is specified

* Add test to ensure keyword inheritance is working for become

* Add clog frag

* Cache fattributes to prevent re-calculation

* ci_complete

* Remove unnecessary getattr.
(cherry picked from commit 420564c5bc)

Co-authored-by: Matt Martz <matt@sivel.net>

* Remove unneeded merge conflict changes
pull/79068/head
Matt Martz 3 years ago committed by GitHub
parent cd52ae459d
commit cd9ef334d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
bugfixes:
- keyword inheritance - Ensure that we do not squash keywords in validate
(https://github.com/ansible/ansible/issues/79021)

@ -211,7 +211,7 @@ class FieldAttributeBase:
method(attribute, name, getattr(self, name))
else:
# and make sure the attribute is of the type it should be
value = getattr(self, name)
value = getattr(self, f'_{name}', Sentinel)
if value is not None:
if attribute.isa == 'string' and isinstance(value, (list, dict)):
raise AnsibleParserError(

@ -298,8 +298,10 @@ class Block(Base, Conditional, CollectionSearch, Taggable):
'''
Generic logic to get the attribute or parent attribute for a block value.
'''
extend = self.fattributes.get(attr).extend
prepend = self.fattributes.get(attr).prepend
fattr = self.fattributes[attr]
extend = fattr.extend
prepend = fattr.prepend
try:
# omit self, and only get parent values

@ -461,8 +461,10 @@ class Task(Base, Conditional, Taggable, CollectionSearch):
'''
Generic logic to get the attribute or parent attribute for a task value.
'''
extend = self.fattributes.get(attr).extend
prepend = self.fattributes.get(attr).prepend
fattr = self.fattributes[attr]
extend = fattr.extend
prepend = fattr.prepend
try:
# omit self, and only get parent values

@ -0,0 +1,3 @@
shippable/posix/group4
context/controller
needs/target/setup_test_user

@ -0,0 +1,3 @@
- command: whoami
register: result
failed_when: result.stdout_lines|first != 'ansibletest0'

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eux
ANSIBLE_ROLES_PATH=../ ansible-playbook -i ../../inventory test.yml "$@"

@ -0,0 +1,8 @@
- hosts: testhost
gather_facts: false
become_user: ansibletest0
become: yes
roles:
- role: setup_test_user
become_user: root
- role: whoami
Loading…
Cancel
Save