如何解决使用 Ansible 管理 ESXI 库存
我正在尝试使用 Ansible 修改一组 ESXI 服务器上的 DNS 设置。我已经能够让我的剧本像这样更改单个服务器上的设置:
---
- hosts: localhost
tasks:
- name: Configure ESXi hostname and DNS servers
vmware_dns_config:
hostname: 'myesxiserver.domain.local'
username: 'username'
password: 'password'
dns_servers:
- x.x.x.x
- x.x.x.x
delegate_to: localhost
我怎样才能让它在多台服务器上工作? Ansible 文档提供了以下示例:
---
- hosts: localhost
tasks:
- name: Configure ESXi hostname and DNS servers
vmware_dns_config:
hostname: '{{ esxi_hostname }}'
username: '{{ esxi_username }}'
password: '{{ esxi_password }}'
change_hostname_to: esx01
domainname: foo.org
dns_servers:
- 8.8.8.8
- 8.8.4.4
delegate_to: localhost
我不清楚如何遍历主机列表并将正确的值传递给我的每个服务器的变量“{{ esxi_hostname }}”。我假设可以使用清单文件传递变量,但我还没有找到任何关于如何为 ESXI 服务器执行此操作的好示例。
解决方法
所以我确实得到了这个工作。
public class AdminUserClient
{
public long Id { get; set; }
[Required]
public ApplicationUser User { get; set; }
[Required]
public Client Client { get; set; }
[Required]
public DateTime CreatedOn { get; set; }
}
public class ApplicationUser : IdentityUser
{
public UserNotificationsSetting NotificationSetting { get; set; }
[JsonIgnore]
public ClientUserRole ClientUserRole { get; set; }
public bool Locked { get; set; }
public string Name { get; set; }
}
public class Client
{
public long Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool RequireTwoFactor { get; set; }
public ApplicationUser CreatedBy { get; set; }
public DateTime CreatedOn { get; set; }
[JsonIgnore]
public ICollection<ClientUserRole> ClientUserRoles { get; set; }
public bool IsDeleted { get; set; }
public bool Locked { get; set; }
}
public class ClientUserRole
{
public long Id { get; set; }
[Required]
public long ClientId { get; set; }
[JsonIgnore]
public Client Client { get; set; }
[Required]
public string UserId { get; set; }
public ApplicationUser User { get; set; }
[Required]
public ApplicationUser CreatedBy { get; set; }
[Required]
public DateTime CreatedOn { get; set; }
[Required]
[Column(TypeName = "nvarchar(15)")]
public UserRole Role { get; set; }
}
我必须使用 vars_file 传递主机名列表,并使用 loop 关键字遍历它。我尝试将 {{inventory_hostname}} 变量与标准清单文件一起使用,但由于 ESXi 服务器上通常默认不启用 SSH,因此我会收到 SSH 连接错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。