0

I'm working on the project and I'm stuck right now. My question is I'm trying to deploy aws lambda function using ansible tower temple and we have multiple aws account but naming standard include dev or prod. Is there a way and any example that show's how to include inventory name in ansible script.

For example under ansible tower (inventories), I have few inventories like "example-dev-standard, "example-prod-standard" and I just want to take the prod or dev out of that name using regex and make it as a variable which I'm also using this variable on other place in the script

- name: Set environment fact
  set_fact:
    test: "{{ ???????? | regex_replace('(?i).*(dev|prod).*', '\\1') | lower }}"

# Test test var
- name: Ensure test fact is either dev or prod
  assert:
    that: test == "dev" or test == "prod"
    msg: "Error: the test fact was not set properly, check the account alias to ensure the string dev or prod exists"
  • "help me" questions are discouraged in SO unless you have tried different methods without reaching a solution, so please post the methods you have tried so that the community doesn't waste time and energy in suggesting methods that were already tried by you – Dhruvan Ganesh Oct 18 '19 at 20:44
  • I have tested the script locally using aws-cli, it working fine but running through tower is where it's failing. I'm just new to this, so I'm still researching how to extract from inventory env variable which set up like "account_name:example-dev-standard" into my script. From locally,I was currently using this trick to get the account info but it's not working from tower ``` - name: Get the current caller identity facts local_action: module: aws_caller_facts register: caller_facts – – redskull Oct 18 '19 at 21:33

0 Answers0