user3423536
user3423536

Reputation: 87

Remove slashes and quotes

I've written the following Ansible to access Azure for automation I'm building.

This is the output, "msg": "\"6d23f7f3-b712-421d-a911-ec73cd18ff8b\", \"ansible\", \"Wfq5-rdMKpv_5HWvr5SJzkzMVfnExVRpv_\", \"5f6e5ef8-7687-487b-a682-15830393472b\"" I want to remove the slashes and quotes in order to use the values in the create-for-rbac command.

Also, I don't know whether I can loop through set_facts instead of having 4-separate commands.

- hosts: localhost
  connection: local
  gather_facts: yes

  tasks:

  #{
  #  "appId": "6d23f7f3-b712-421d-a911-ec73cd18ff8b",
  #  "displayName": "ansible",
  #  "password": "tsiQh~gR4S-IBHi8VBoPtWlYTS~r~jE8KF",
  #  "tenant": "5f6e5ef8-7687-487b-a682-15830393472b"
  #}

  - name:
    command: az ad sp create-for-rbac --name ansible --role Contributor
    register: rbac

  - name:
    set_fact:
      appId: "{{ rbac.stdout_lines.1.split().1 }}"
  - name:
    set_fact:
      displayName: "{{ rbac.stdout_lines.2.split().1 }}"
  - name:
    set_fact:
      password: "{{ rbac.stdout_lines.3.split().1 }}"
  - name:
    set_fact:
      tenant: "{{ rbac.stdout_lines.4.split().1 }}"

  - name:
    debug:
      msg: "{{ appId }} {{ displayName }} {{ password }} {{ tenant }}"


#  - name: Create an Azure service principal
#    command: az login --service-principal -u "{{ myAppID }}" -p "{{ mypasswd }}" --tenant "{{ mytenant }}"

Upvotes: 0

Views: 215

Answers (1)

LaM0uette
LaM0uette

Reputation: 73

hi i think this should work: (?<=["\])\b.*?\b(?=["\])

My Exemple : https://regex101.com/r/rb2Sq9/1

Upvotes: 1

Related Questions