从命令行传递的ansible-playbook额外var

时间:2020-01-03 15:29:05

标签: linux variables ansible

我的剧本看起来像:

---

- name: Install and configure AD authentication
  hosts: test
   become: yes
   become_user: root

  vars:
    hostname: "{{ host_name }}"


  vars_prompt:
    - name: "bind_password"
      prompt: "Password for xxx.local\\user"
      private: yes

  tasks:

    - name: Ansible prompt example.
      debug:
        msg: "{{ bind_password }}"

    - name: Ansible prompt example.
      debug:
        msg: "{{ host_name }}"

我正在使用以下命令来传递变量 ansible-playbook hostname_set.yml --extra-vars“ host_name ='xxx.xxx.local'”

但是我没有获得用于设置主机名的确切变量值。

Password for xxx.xxx\user:
PLAY [Install and configure AD authentication] 
TASK [Gathering Facts] 
 ok: [x.x.x.x]
TASK [Ansible prompt example.] 
     ok: [x.x.x.x] => {
        "msg": "wel"
}
TASK [Ansible prompt example.] 
ok: [x.x.x.x] => {
    "msg": ""
}
 TASK [Setup the hostname] 
 changed: [x.x.x.x]
 PLAY RECAP 
 x.x.x.x              : ok=4    changed=1    unreachable=0    failed=0    
 skipped=0    rescued=0    ignored=0

1 个答案:

答案 0 :(得分:0)

您的命令行中有多余的空间,这会破坏ansible解释多余的var的方式。只需将其删除:

public partial class Parties { public Parties() { Image = new HashSet<Image>(); PartyParticipants = new HashSet<PartyParticipants>(); } public int Id { get; set; } public string Name { get; set; } public DateTime PartyDate { get; set; } public DateTime CreatedDate { get; set; } public int ParticipantCount { get; set; } public int MaxParticipant { get; set; } public string PartySplash { get; set; } public string ShortDescription { get; set; } public string Description { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } public bool EntranceFree { get; set; } public int? FreeParticipant { get; set; } public int? FreeParticipantMax { get; set; } public int UserId { get; set; } public virtual Users User { get; set; } public virtual ICollection<Image> Image { get; set; } public virtual ICollection<PartyParticipants> PartyParticipants { get; set; } }

请注意,您甚至不需要所有这些引号。以下内容也应按预期工作:

--extra-vars "host_name='xxx.xxx.local'"