Ansible库存分组

时间:2019-06-08 14:33:35

标签: ansible ansible-2.x ansible-inventory

我在以下剧本中定义了ansible过滤选项。但是,当使用centos用户执行时,它不是由用户筛选运行的。我必须与3个不同的用户一起运行此剧本3次:

1. centos 
2. ec2-user
3. admin 

这就是我的执行方式

1. ansible-playbook -i inventory -u admin   group_by.yaml
2. ansible-playbook -i inventory -u ec2-user   group_by.yaml
3. ansible-playbook -i inventory -u centos   group_by.yaml

问题是remote_user无法正常工作。它正在过滤和分组。

--- 
- name: Run tasks based on OS
  hosts: all 
  tasks: 
    - name: Group OS
      group_by: 
        key: "{{ ansible_distribution }}"

- hosts: CentOS
  become: yes
  become_user: root
  remote_user: centos
  tasks:
    - name: Install on centos 
      package: 
        name: telnet
        state: absent

- hosts: Amazon
  become: yes
  become_user: root
  remote_user: ec2-user
  tasks:
    - name: Install on ec2 
      package: 
        name: telnet

- hosts: Debian
  become: yes
  become_user: root
  remote_user: admin
  tasks:
    - name: Install on debian 
      package: 
        name: telnet

我已经多次运行该命令。它正在选择我的默认用户。 Remote_user无法在剧本中使用。

0 个答案:

没有答案