run with_items loop using python api.

7 views
Skip to first unread message

Google Pixel

unread,
Aug 17, 2021, 6:22:01 AMAug 17
to Ansible Development
for a bigger project we are interfacing ansible with python using the python api. 

however I am not able to run the debug module using a with_items loop. 
the purpose is to find/report and delete the files found on remote systems. 

play_source = dict(
    name="Ansible Play",
    hosts='all',
    gather_facts='no',
    vars=dict(sudo_content=sudoers_content),
    tasks=[
        dict(action=dict(module='find',
                         file_type='file',
                         paths = '/etc',
                         age= '14d',
                         use_regex = 'True',
                         patterns='sudoers(?=\\.).*'), register='output'),
        dict(action=dict(module='debug', args=dict(msg='{{ item.path}}'), with_items='{{ output.files}}'))

    ]
    )

this executes fine the files are found but the debug task fails due to item variable is undefined.

fatal: [vm]: FAILED! =>
  msg: 'The task includes an option with an undefined variable. The error was: ''item'' is undefined'


how can  i make the loop work? 

thanks 

Reply all
Reply to author
Forward
0 new messages