--- - name: Fetch IAM info uri: url: http://169.254.169.254/latest/meta-data/iam/info return_content: yes register: iamInfo - name: Extract Account ID set_fact: aws_account: "{{ (iamInfo.content|from_json).InstanceProfileArn | regex_replace('^arn:aws:iam::(\\d+):.*','\\\\1') }}"