Create remotly server and still on it to other installations.

15 views
Skip to first unread message

weslley...@ahgora.com.br

unread,
Sep 5, 2016, 10:09:51 PM9/5/16
to Ansible Project
Hello,


I have been working to create a server on Linode via ansible, and i can do it by a playbook but when I try to use it with the best practices(Roles) I am not getting well.

Can anyone help me ?

Basically it creates the linode server and when it goes to the next step which will set hostname it doesnt connect to the server. It fails to connect automatically using the ssh public key.


Using roles :

--------------------------------------------- main playbook-----------------------------------------------

- hosts: localhost
  connection: local
  gather_facts: false



  roles:
     # - users
     # - updates
     # - monitoring
      - linode1



- hosts: linode                           ------- I do get it data from a running playbook
  become: true


  roles:  
      - linodeteste
------------------------------------------------------linode1.yml---------------------------

- include_vars: config.yml

 
- name: Fail if server_hostname is not defined
  fail: msg="server_hostname needs to be defined via commandline, e.g. --extra-vars server_hostname=flower"
  when: server_hostname is not defined

- name: Create linode server via Linode API
  linode:
    name: "{{ server_hostname }}"
    plan: "{{ linode_plan }}"
    datacenter: "{{ linode_datacenter }}"
    distribution: "{{ linode_distribution }}"
    ssh_pub_key: "{{ root_ssh_pub_key }}"
    swap: "{{ linode_swap }}"
    wait: yes
    wait_timeout: 600
    state: present
  register: linode

- name: Show me the registered linode
  debug: var=linode

- name: Add new host to in-memory inventory
  add_host:
    hostname: "{{ linode.instance.ipv4 }}"
    groupname: "linode"

- name: Wait for Linode to listen on port 22
  wait_for:
    state: started
    host: "{{ linode.instance.ipv4 }}"
    port: 22
------------------------------linodeteste.yml------------------------

- include_vars: roles/linode/vars/config.yml

  vars:
      server_fqdn: "{{ server_hostname }}.{{ server_domain }}"


- name: set hostname
  hostname: name="{{ server_hostname }}"


 - name: set FQDN
   lineinfile:
     dest=/etc/hosts
     regexp='{{ item }}$'
     line="{{ item }} {{ server_fqdn }} {{ server_hostname }}"
     state=present
   with_items: groups['linode']
   become: true

 - name: ssh key only
   copy: src=files/ssh/sshd_config dest=/etc/ssh/sshd_config
   notify: restart ssh

- name: Adição de usuarios
  user: name={{ item.name }} shell=/bin/bash state=present groups={{ item.groups }}
  with_items:
     - { name: 'weslley', groups: 'sudo' }
  become: true    

- name: "Autorizando acesso dos usuarios com chave de SSH."
  authorized_key: user={{item.name}} key="{{ lookup('file', 'id_rsa.{{item.name}}.pub') }}" exclusive=yes 
  with_items:
     - { name: 'weslley' }
  become: true
     

   handlers:
     - name: restart ssh
       service: name=ssh state=restarted


My error :

ECDSA key fingerprint is 78:95:7e:35:a4
Are you sure you want to continue connecting (yes/no)? yes
fatal: [66.228.50.17]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
 [WARNING]: Could not create retry file 'pontoweb.retry'.         [Errno 2] No such file or directory: ''




Reply all
Reply to author
Forward
0 new messages