ansible / ansible-modules-core

Ansible modules - these modules ship with ansible
1.3k stars 1.95k forks source link

Bad documentation example in gce module #977

Closed ipv1337 closed 7 years ago

ipv1337 commented 9 years ago

This is the example I'm following, but I end up with different results. You can see below most of the playbook works out fine except for the part when Ansible comes in to do it's magic. For some reason the host cannot be found.

┌─┤[james@xps13-nocentre-net:~/workspace/github/ansible][3.18.8-201.fc21.x86_64 10:51:10]├────── ── ─ └[feature/elk] $ ansible-playbook playbooks/plays/gce/elk.yml -i inventory/hosts_production

PLAY [Google Cloud Procurement] *********************************************** 

TASK: [gce] ******************************************************************* 
ok: [localhost -> 127.0.0.1]

TASK: [set_fact public_ip={{gce.instance_data[0].public_ip}}] ***************** 
ok: [localhost]

TASK: [set_fact private_ip={{gce.instance_data[0].private_ip}}] *************** 
ok: [localhost]

TASK: [set_fact ansible_ssh_host={{public_ip}}] ******************************* 
ok: [localhost]

TASK: [debug msg="{{gce}}"] *************************************************** 
ok: [localhost] => {
    "msg": "{u'instance_data': [{u'status': u'RUNNING', u'name': u'elk-stage-uscentral1a-kernelfire-com', u'zone': u'us-central1-a', u'tags': [], u'image': None, u'disks': [u'elk-stage-uscentral1a-kernelfire-com', u'elk-data-stage-uscentral1a-kernelfire-com'], u'public_ip': u'130.211.122.65', u'private_ip': u'10.240.178.66', u'machine_type': u'n1-standard-4', u'metadata': {}, u'network': u'default'}], u'name': u'elk-stage-uscentral1a-kernelfire-com', u'zone': u'us-central1-a', u'changed': False, u'state': u'present', 'invocation': {'module_name': u'gce', 'module_args': ''}}"
}

TASK: [Wait for SSH to come up] *********************************************** 
ok: [localhost -> 127.0.0.1] => (item={u'status': u'RUNNING', u'network': u'default', u'zone': u'us-central1-a', u'tags': [], u'image': None, u'disks': [u'elk-stage-uscentral1a-kernelfire-com', u'elk-data-stage-uscentral1a-kernelfire-com'], u'public_ip': u'130.211.122.65', u'private_ip': u'10.240.178.66', u'machine_type': u'n1-standard-4', u'metadata': {}, u'name': u'elk-stage-uscentral1a-kernelfire-com'})

TASK: [gce_pd] **************************************************************** 
ok: [localhost -> 127.0.0.1]

TASK: [set_fact gce_pd_name={{gce_pd.name}}] ********************************** 
ok: [localhost]

TASK: [debug msg="{{gce_pd}}"] ************************************************ 
ok: [localhost] => {
    "msg": "{u'size_gb': 100, u'name': u'elk-data-stage-uscentral1a-kernelfire-com', u'zone': u'us-central1-a', u'changed': False, u'state': u'present', u'attached_to_instance': u'elk-stage-uscentral1a-kernelfire-com', 'invocation': {'module_name': u'gce_pd', 'module_args': ''}, u'disk_type': u'pd-ssd', u'attached_mode': u'READ_WRITE'}"
}

TASK: [debug msg="{{gce_pd_name}}"] ******************************************* 
ok: [localhost] => {
    "msg": "elk-data-stage-uscentral1a-kernelfire-com"
}

PLAY [Ansible Provisioning] *************************************************** 
skipping: no hosts matched

PLAY RECAP ******************************************************************** 
localhost                  : ok=10   changed=0    unreachable=0    failed=0   

============= PLAYBOOK ==============

- name: Google Cloud Procurement
  hosts: localhost
  connection: local
  gather_facts: false
  tasks:
  - local_action:
      module: gce
      image: centos-6
      machine_type: n1-standard-4
      name: elk-stage-uscentral1a-kernelfire-com
      persistent_boot_disk: true
      project_id: cf-stage
      zone: us-central1-a
    register: gce
  - set_fact: public_ip={{gce.instance_data[0].public_ip}}
  - set_fact: private_ip={{gce.instance_data[0].private_ip}}
  - set_fact: ansible_ssh_host={{public_ip}}
  - debug: msg="{{gce}}"

  - name: Wait for SSH to come up
    local_action: wait_for host={{item.public_ip}} port=22 delay=10 timeout=60 state=started
    with_items: "{{gce.instance_data}}"

  - local_action:
      module: gce_pd
      disk_type: pd-ssd
      instance_name: "{{gce.instance_data[0].name}}"
      mode: READ_WRITE
      name: elk-data-stage-uscentral1a-kernelfire-com
      project_id: cf-stage
      size_gb: 100
      zone: us-central1-a
    register: gce_pd
  - set_fact: gce_pd_name={{gce_pd.name}}
  - debug: msg="{{gce_pd}}"
  - debug: msg="{{gce_pd_name}}"

- name: Ansible Provisioning
  hosts: launched
  sudo: true
  roles:
  - { role: elasticsearch, tags: [ 'extended', 'elasticsearch' ] }
  - { role: redis, tags: [ 'extended', 'redis' ] }
  - { role: logstash, tags: [ 'extended', 'logstash' ] }
  - { role: kibana, tags: [ 'extended', 'kibana' ] }

Any ideas?

bcoca commented 9 years ago

you might want to include an "add_hosts" task to put the new hosts into the 'launched' group

ansibot commented 8 years ago

@erjohnso, ping. This issue is still waiting on your response. click here for bot help

erjohnso commented 8 years ago

/cc @supertom

ansibot commented 8 years ago

@supertom, ping. This issue is still waiting on your response. click here for bot help

ansibot commented 7 years ago

@supertom, ping. This issue is still waiting on your response. click here for bot help