简体   繁体   中英

AnsibleFileNotFound error during Ansible playbook execution via AWS SSM

I zipped up an Ansible playbook and a configuration file, pushed the.zip file to S3, and I'm triggering the Ansible playbook from AWS SSM.

I'm getting a AnsibleFileNotFound error: AnsibleFileNotFound: Could not find or access '/path/to/my_file.txt' on the Ansible Controller.

Here is my playbook:

- name: Copies a configuration file to a machine.
  hosts: 127.0.0.1
  connection: local
  tasks:
    - name: Copy the configuration file.  
      copy:
        src: /path/to/my_file.txt
        dest: /etc/my_file.txt
        owner: root
        group: root
        mode: '0644'
      become: true

my_file.txt exists in the.zip file that I uploaded to S3, and I've verified that it's being extracted (via the AWS SSM output). Why wouldn't I be able to copy that file over? What do I need to do to get Ansible to save this file to /etc/ on the target machine?

EDIT:

  • Using remote_src: true makes sense because the.zip file is presumably unpacked by AWS SSM to somewhere on the target machine. The problem is that this is unpacked to a random temp directory, so the file isn't found anyway.
  • I tried a couple of different absolute paths - I am assuming the path here is relevant to the.zip root.

The solution here is a bit horrendous:

  1. The.zip file is extracted to the machine into an ephemeral directory with a random name which is not known in advance of the AWS SSM execution.
  2. remote_src must be true . Yeah, it's your file that you've uploaded to S3, but Ansible isn't really smart enough to know that in this context.
  3. A path relative to the playbook has to be used if you're bundling configuration files with the playbook.
  4. That relative path has to be interpolated.

So using src: "{{ playbook_dir | dirname }}/path/to/my_file.txt" solved the problem in this case.

Note that this approach should not be used if configuration files contain secrets, but I'm not sure what approach AWS SSM offers for that type of scenario when you are using it in conjunction with Ansible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM