我想在没有become指令的情况下运行“ssh”角色,并运行使用become指令运行的其他角色我决定创建另一个ansible_ssh.cfg
不包含becomes语句的配置文件,并将其归因于ssh角色
我尝试了这个(在tasks/ssh.yml中):
- name: deploiement clé ssh
environment:
ANSIBLE_CONFIG: ansible_ssh.cfg
authorized_key:
user: "{{ansible_user_id}}"
state: present
key: "{{ lookup('file', '/home/{{ansible_user_id}}/.ssh/id_rsa.pub') }}"
并且(在角色级别):
roles:
- ssh
environment:
ANSIBLE_CONFIG: /var/lib/rundeck/ansible/roles:ssh/files/ansible_ssh.cfg
- proxy
- vmware_tools
- ntp
- nmap
- tcpdump
- unattended-upgrades
- traceroute
- apache
- mysql
但没有成功
安塞波版本:2.7
答案1
become: false
您可以在每次播放的基础上定义和覆盖许多配置设置(例如)
例如:
---
- hosts: 192.168.1.2
tasks:
- name: some task
shell: foo
- hosts: 192.168.1.2
become: false
roles: my_ssh_role
答案2
我已经建立了一些有效的东西:
---
- hosts: slaves
strategy: free
# connection: network_cli
become: no
roles:
- ssh
- name: import playbbok
import_playbook: suite_config_linux.yml
我创建了另一个剧本,用become: no
它调用 ssh 角色,第二个剧本用import_playbook
(include
将在 2.8 版本的 Ansible 中消失)
---
- hosts: slaves
strategy: free
# connection: network_cli
roles:
# - ssh
- proxy
- vmware_tools
- ntp
- nmap
- tcpdump
- unattended-upgrades
- traceroute
- apache
- mysql