1

I would like to run the 'ssh' role without the become directive and run my others roles run with the become directive I decided to create an another config file ansible_ssh.cfg which not contains the becomes statements, and attribute it to the ssh role

I tried this (in 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') }}"

and that (at role level):

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

But without success

Ansible version: 2.7

  • Hi Ludo and welcome to StackExchange. Since it looks like 0xSheepdog's answer has solved your problem, please mark it as "accepted" (the tick next to the answer) to help other users find the answer easier and give kudos to the author. – mhutter Apr 26 at 13:25
2

You can define and override many config settings (like become: false) on per-play basis

For example:

---
- hosts: 192.168.1.2
  tasks:
  - name:  some task
    shell: foo

- hosts: 192.168.1.2
  become: false
  roles:  my_ssh_role
0

I've founded something that works:

---
 - hosts: slaves
   strategy: free
#   connection: network_cli
   become: no
   roles:
      - ssh
 - name: import playbbok
   import_playbook: suite_config_linux.yml

I created an another playbook with become: no which call the ssh role and the second playbook with import_playbook ( include will disappear in 2.8 version of Ansible)

---
 - hosts: slaves
   strategy: free
#   connection: network_cli
   roles:
#      - ssh
      - proxy
      - vmware_tools
      - ntp
      - nmap
      - tcpdump
      - unattended-upgrades
      - traceroute
      - apache
      - mysql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.