build_ami.yml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ---
  2. - hosts: localhost
  3. connection: local
  4. gather_facts: no
  5. tasks:
  6. - name: Require openshift_aws_base_ami
  7. fail:
  8. msg: "A base AMI is required for AMI building. Please ensure `openshift_aws_base_ami` is defined."
  9. when: openshift_aws_base_ami is undefined
  10. - name: "Alert user to variables needed and their values - {{ item.name }}"
  11. debug:
  12. msg: "{{ item.msg }}"
  13. with_items:
  14. - name: openshift_aws_clusterid
  15. msg: "openshift_aws_clusterid={{ openshift_aws_clusterid | default('default') }}"
  16. - name: openshift_aws_region
  17. msg: "openshift_aws_region={{ openshift_aws_region | default('us-east-1') }}"
  18. - name: create an instance and prepare for ami
  19. include_role:
  20. name: openshift_aws
  21. tasks_from: build_ami.yml
  22. vars:
  23. openshift_aws_node_group_type: compute
  24. - name: fetch newly created instances
  25. ec2_remote_facts:
  26. region: "{{ openshift_aws_region | default('us-east-1') }}"
  27. filters:
  28. "tag:Name": "{{ openshift_aws_base_ami_name | default('ami_base') }}"
  29. instance-state-name: running
  30. register: instancesout
  31. retries: 20
  32. delay: 3
  33. until: instancesout.instances|length > 0
  34. - name: wait for ssh to become available
  35. wait_for:
  36. port: 22
  37. host: "{{ instancesout.instances[0].public_ip_address }}"
  38. timeout: 300
  39. search_regex: OpenSSH
  40. - name: add host to nodes
  41. add_host:
  42. groups: nodes
  43. name: "{{ instancesout.instances[0].public_dns_name }}"
  44. - hosts: nodes
  45. gather_facts: False
  46. tasks:
  47. - name: set the user to perform installation
  48. set_fact:
  49. ansible_ssh_user: "{{ openshift_aws_build_ami_ssh_user | default('root') }}"
  50. - name: normalize groups
  51. include: ../../byo/openshift-cluster/initialize_groups.yml
  52. - name: run the std_include
  53. include: ../../common/openshift-cluster/evaluate_groups.yml
  54. - name: run the std_include
  55. include: ../../common/openshift-cluster/initialize_facts.yml
  56. - name: run the std_include
  57. include: ../../common/openshift-cluster/initialize_openshift_repos.yml
  58. - name: run node config setup
  59. include: ../../common/openshift-node/setup.yml
  60. - name: run node config
  61. include: ../../common/openshift-node/configure_nodes.yml
  62. - name: Re-enable excluders
  63. include: ../../common/openshift-node/enable_excluders.yml
  64. - hosts: localhost
  65. connection: local
  66. become: no
  67. tasks:
  68. - name: seal the ami
  69. include_role:
  70. name: openshift_aws
  71. tasks_from: seal_ami.yml
  72. vars:
  73. openshift_aws_ami_name: "openshift-gi-{{ lookup('pipe', 'date +%Y%m%d%H%M')}}"