运行 ansible playbook 从 ansible tower 到 stop/start azure vm 时无法获取凭据
Failed to get credentials when running ansible playbook from ansible tower to stop/start azure vm
我是 运行 从 ansible tower 到 stop/start vm 的 ansible playbook。下面是代码。
---
- hosts: localhost
gather_facts: yes
vars:
state : "{{ state }}"
env:
ARM_SUBSCRIPTION_ID : "{{ subscription_id }}"
ARM_TENANT_ID : "{{ tenant_id }}"
ARM_CLIENT_ID : "{{ client_id }}"
ARM_CLIENT_SECRET : "{{ secret_value }}"
collections:
- ansible.tower
tasks:
- name: Power Off
azure_rm_virtualmachine:
resource_group: "{{ resource_group_name }}"
name: "{{ virtual_machine_name }}"
started: no
when: state == "stop"
- name: Deallocate
azure_rm_virtualmachine:
resource_group: "{{ resource_group_name }}"
name: "{{ virtual_machine_name }}"
allocated: no
when: state == "delete"
- name: Power On
azure_rm_virtualmachine:
resource_group: "{{ resource_group_name }}"
name: "{{ virtual_machine_name }}"
when: state == "start"
environment: "{{ env }}"
这是给出以下错误:
致命:[本地主机]:失败! => {"changed": false, "msg": "无法获取凭据。要么作为参数传递,设置环境变量,在 ~/.azure/credentials 中定义配置文件,要么使用 Azure CLI (az login
)."}
语法方面一切看起来都不错。请帮忙。
您可以将凭据作为环境变量传递,如下所示。
- name: Restart
azure_rm_virtualmachine:
resource_group: "{{ resource_group_name }}"
name: "{{ virtual_machine_name }}"
restarted: yes
subscription_id : "{{ subscription_id }}"
tenant : "{{ tenant_id }}"
client_id : "{{ client_id }}"
secret : "{{ secret_value }}"
when: state == "restart"
我是 运行 从 ansible tower 到 stop/start vm 的 ansible playbook。下面是代码。
---
- hosts: localhost
gather_facts: yes
vars:
state : "{{ state }}"
env:
ARM_SUBSCRIPTION_ID : "{{ subscription_id }}"
ARM_TENANT_ID : "{{ tenant_id }}"
ARM_CLIENT_ID : "{{ client_id }}"
ARM_CLIENT_SECRET : "{{ secret_value }}"
collections:
- ansible.tower
tasks:
- name: Power Off
azure_rm_virtualmachine:
resource_group: "{{ resource_group_name }}"
name: "{{ virtual_machine_name }}"
started: no
when: state == "stop"
- name: Deallocate
azure_rm_virtualmachine:
resource_group: "{{ resource_group_name }}"
name: "{{ virtual_machine_name }}"
allocated: no
when: state == "delete"
- name: Power On
azure_rm_virtualmachine:
resource_group: "{{ resource_group_name }}"
name: "{{ virtual_machine_name }}"
when: state == "start"
environment: "{{ env }}"
这是给出以下错误:
致命:[本地主机]:失败! => {"changed": false, "msg": "无法获取凭据。要么作为参数传递,设置环境变量,在 ~/.azure/credentials 中定义配置文件,要么使用 Azure CLI (az login
)."}
语法方面一切看起来都不错。请帮忙。
您可以将凭据作为环境变量传递,如下所示。
- name: Restart
azure_rm_virtualmachine:
resource_group: "{{ resource_group_name }}"
name: "{{ virtual_machine_name }}"
restarted: yes
subscription_id : "{{ subscription_id }}"
tenant : "{{ tenant_id }}"
client_id : "{{ client_id }}"
secret : "{{ secret_value }}"
when: state == "restart"