0

I am automating the creation of my Angular/Amplify project using Ansible. I am stuck on running amplify init in Ansible. amplify init requires the use of the up arrow and down arrow keys to navigate its menus.

I can use Ansible expect to accept defaults and specify a literal string for some answers, but the arrow keys are required to specify things like the profile.

John McGehee
  • 9,117
  • 9
  • 42
  • 50

1 Answers1

0

AWS Amplify headless mode allows you to specify amplify init arguments as string literals without navigating menus using arrow keys. I use the --amplify argument to specify the environment, and --providers to specify the Amplify administrator profile. --yes means to accept the defaults for everything else.

Here is my play that runs amplify init. It presumes that you have already created your Angular (or other framework) project. It depends on predefined variables amplify_project_dir and amplify_project_administrator_profile:

- name: Initialize Amplify for this project
  command:
    chdir: "{{ amplify_project_dir }}"
    cmd: >
      amplify init
        --yes
        --amplify
          {\"envName\":\"dev\"}
        --providers
          {\"useProfile\":true,\"profileName\":\"{{ amplify_project_administrator_profile }}\"}
    creates: "{{ amplify_project_dir }}/amplify/"

The JSON argument values must contain no unescaped whitespace. Jinja2 eliminates the whitespace in {{ amplify_project_administrator_profile }}.

John McGehee
  • 9,117
  • 9
  • 42
  • 50