多个远程用户使用可靠的动态库存

问题描述 投票:0回答:2

我正在使用动态清单,但我没有找到任何关于如何与多个用户一起运行剧本的信息。 当我在 ansible.cfg 文件中配置特定的远程用户时,ssh 连接仅适用于使用该特定用户的操作系统类型。 我什至不确定应该在哪里配置? 在剧本本身中,我已配置为使用不同的操作系统类型。 我知道它也适用于静态清单文件,但我不知道如何使用动态清单配置它。 我正在使用 ansible galaxy 角色作为 ansible 剧本运行:https://galaxy.ansible.com/geerlingguy/docker 我尝试配置 group_vars 但它不起作用。 我需要能够使用相同的剧本,通过 ssh 连接到我使用不同用户的所有实例。

这就是我的动态库存的样子:

plugin: aws_ec2

regions:

  - "us-east-1"

keyed_groups:

  - key: tags.Ansible

  - key: tags.Name


filters:

  tag:Ansible:

    - ubuntu

    - redhat


compose:

  ansible_host: public_ip_address

这是我运行的剧本:

---

# docker.yml


- name: Use a galaxy role to install docker

  hosts: "all"

  become: true


  roles:

    - role: "geerlingguy.docker"

      tags: ["docker"]
amazon-ec2 ssh ansible ansible-inventory ansible-role
2个回答
0
投票

我之前的回答看起来不太好评论:

插件:amazon.aws.aws_ec2

地区:

  • us-east-1

keyed_groups:

  • key: tags.Ansible 前缀:tag_Name_ 分隔符:“”

过滤器: 标签:Ansible: - Ubuntu - 红帽

团体: ubuntu:“(标签|列表)中的'ubuntu'” redhat:“(标签|列表)中的'redhat'”

撰写: ansible_host: public_ip_address


0
投票

这是我的问题的答案:

# demo.aws_ec2.yml
plugin: amazon.aws.aws_ec2
regions:
  - us-east-1
keyed_groups:
  # add hosts to tag_Name_value groups for each aws_ec2 host's tags.Name variable.
  - key: tags.Ansible
    prefix: tag_Name_
    separator: ""
filters:
  tag:Ansible:
    - ubuntu
    - redhat
    
groups:
  # add hosts to the group ubuntu or redhat
  ubuntu: "'ubuntu' in (tags|list)"
  redhat: "'redhat' in (tags|list)"
  
compose:
  ansible_host: public_ip_address
© www.soinside.com 2019 - 2024. All rights reserved.