title: Unable to get part of a play to run locally in Ansible
body: <p>This is all running within AWX which is hosted on-prem. I'm trying to manage some EC2 instances within AWS. I've setup the bastion jump and can get all my other plays to work correctly.</p>
  <p>However there is one simple job template I want to provide to a few devs. Essentially when they make a change to the code, it enables opcache to be cleared and invalidates the specific files in CloudFront.</p>
  <p>I want the CloudFront API Call (cloudfront_invalidations module) to run off AWX locally and then if this is successful, notify the two web servers instances to restart their PHP and Apache process.</p>
  <pre><code>---
  - name: Restart httpd and php-fpm
    remote_user: ec2-user
    hosts: all
    become: true
  
    tasks:
      - name: Invalidate paths in CloudFront
        cloudfront_invalidation:
          distribution_id: &quot;{{ distribution_id }}&quot;
          aws_access_key: &quot;{{ aws_access_key }}&quot;
          aws_secret_key: &quot;{{ aws_secret_key }}&quot;
          target_paths: &quot;{{ cloudfront_invalidations.split('\n') }}&quot;
        delegate_to: 127.0.0.1
        notify:
          - Restart service httpd
          - Restart service php-fpm
    
    handlers:
      - name: Restart service httpd
        service:
          name: httpd
          state: restarted
  
      - name: Restart service php-fpm
        service:
          name: php-fpm
          state: restarted
  </code></pre>
  <p>However when running the play it seems to ignore the 'delegate_to' action and instead runs the invalidation twice, for each host. I'm unsure if it's actually running locally. I've tried adding the run_once flag, but this only then restarted httpd + PHP on one host.</p>
  <p>Any ideas?</p>