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
pull/79071/head
Matt Martz 2 years ago committed by GitHub
parent 11c1777d56
commit 420564c5bc
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)) method(attribute, name, getattr(self, name))
else: else:
# and make sure the attribute is of the type it should be # 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 value is not None:
if attribute.isa == 'string' and isinstance(value, (list, dict)): if attribute.isa == 'string' and isinstance(value, (list, dict)):
raise AnsibleParserError( 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. Generic logic to get the attribute or parent attribute for a block value.
''' '''
extend = self.fattributes.get(attr).extend fattr = self.fattributes[attr]
prepend = self.fattributes.get(attr).prepend
extend = fattr.extend
prepend = fattr.prepend
try: try:
# omit self, and only get parent values # 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. Generic logic to get the attribute or parent attribute for a task value.
''' '''
extend = self.fattributes.get(attr).extend fattr = self.fattributes[attr]
prepend = self.fattributes.get(attr).prepend
extend = fattr.extend
prepend = fattr.prepend
try: try:
# omit self, and only get parent values # 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

@ -2,9 +2,11 @@
hosts: testhost hosts: testhost
gather_facts: false gather_facts: false
become: yes become: yes
# become_user needed at play level for testing this behavior
become_user: nobody become_user: nobody
roles: roles:
- name: setup_test_user - name: setup_test_user
become_user: root
tasks: tasks:
- shell: whoami - shell: whoami
register: inherited register: inherited

Loading…
Cancel
Save