ansible/cloud_providers/ec2_infrastructure_deployment.yml
@@ -213,6 +213,10 @@ debug: var: hostvars verbosity: 2 - name: debug groups debug: var: groups verbosity: 2 - name: Configure local ssh config for bastion proxy use include: "{{ANSIBLE_REPO_PATH}}/cloud_providers/{{cloud_provider}}_ssh_config_setup.yml" ansible/configs/ans-tower-lab/README.adoc
@@ -32,6 +32,8 @@ satellite_org: Sat_org_name satellite_activationkey: "rhel7basic" # tower tower_license: '{"eula_accepted" : "true", "company_name": "Red Hat Internal", "contact_email": "jonsnow@redhat.com", "contact_name": "Jon Snow", "instance_count": 16, "license_date": 1514782800, "license_key": "xxxxx", "license_type": "enterprise", "subscription_name": "Ansible Tower by Red Hat, Standard (16 Managed Nodes)", "trial": false }' ---- == Review the Env_Type variable file @@ -46,8 +48,8 @@ [source,bash] ---- REGION=ap-southeast-2 KEYNAME=ocpkey GUID=hostnametest1 KEYNAME=bennokey GUID=testbenno1 ENVTYPE="ans-tower-lab" CLOUDPROVIDER=ec2 HOSTZONEID='Z3IHLWJZOU9SRT' @@ -69,8 +71,8 @@ -e "email=name@example.com" \ -e "install_ipa_client=false" \ -e "repo_method=file" -e "own_repo_path=${REPO_PATH}" -e "repo_version=${REPO_VERSION}" \ -e "software_to_deploy=none" ---- -e "software_to_deploy=tower" -e"deploy_tower_demo=true" --- === To Delete an environment ---- ansible/configs/ans-tower-lab/env_secret_vars.yml
ansible/configs/ans-tower-lab/post_software.yml
@@ -46,6 +46,15 @@ state: restarted when: install_ipa_client - name: Post Tower configs hosts: towers[0] become: yes vars_files: - "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/env_vars.yml" roles: - { role: "{{ ANSIBLE_REPO_PATH }}/roles/tower_demo", when: deploy_tower_demo | bool } - name: PostSoftware flight-check hosts: localhost connection: local ansible/files/tower_cli.j2
New file @@ -0,0 +1,10 @@ username: admin description_on: False host: 127.0.0.1 verbose: False certificate: format: human color: True password: {{ tower_admin_password }} verify_ssl: False use_token: False ansible/files/tower_license
ansible/main.yml
@@ -1,5 +1,6 @@ # vim: set ft=ansible: --- ################################################################################ ################################################################################ ############ Step 000 Pre Infrastructure Deploy Tasks @@ -42,8 +43,8 @@ - name: Pre Software include: "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/pre_software.yml" tags: - step003 - pre_software_tasks - step003 - pre_software_tasks ################################################################################## ################################################################################## ansible/roles/tower_demo/README.md
New file @@ -0,0 +1,38 @@ Role Name ========= A brief description of the role goes here. Requirements ------------ Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. Role Variables -------------- A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. Dependencies ------------ A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. Example Playbook ---------------- Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - hosts: servers roles: - { role: username.rolename, x: 42 } License ------- BSD Author Information ------------------ An optional section for the role authors to include contact information, or a website (HTML is not allowed). ansible/roles/tower_demo/defaults/main.yml
New file @@ -0,0 +1,2 @@ --- # defaults file for tower_demo ansible/roles/tower_demo/handlers/main.yml
New file @@ -0,0 +1,2 @@ --- # handlers file for tower_demo ansible/roles/tower_demo/meta/main.yml
New file @@ -0,0 +1,57 @@ galaxy_info: author: your name description: your description company: your company (optional) # If the issue tracker for your role is not on github, uncomment the # next line and provide a value # issue_tracker_url: http://example.com/issue/tracker # Some suggested licenses: # - BSD (default) # - MIT # - GPLv2 # - GPLv3 # - Apache # - CC-BY license: license (GPLv2, CC-BY, etc) min_ansible_version: 1.2 # If this a Container Enabled role, provide the minimum Ansible Container version. # min_ansible_container_version: # Optionally specify the branch Galaxy will use when accessing the GitHub # repo for this role. During role install, if no tags are available, # Galaxy will use this branch. During import Galaxy will access files on # this branch. If Travis integration is configured, only notifications for this # branch will be accepted. Otherwise, in all cases, the repo's default branch # (usually master) will be used. #github_branch: # # platforms is a list of platforms, and each platform has a name and a list of versions. # # platforms: # - name: Fedora # versions: # - all # - 25 # - name: SomePlatform # versions: # - all # - 1.0 # - 7 # - 99.99 galaxy_tags: [] # List tags for your role here, one per line. A tag is a keyword that describes # and categorizes the role. Users find roles by searching for tags. Be sure to # remove the '[]' above, if you add tags to this list. # # NOTE: A tag is limited to a single word comprised of alphanumeric characters. # Maximum 20 tags per role. dependencies: [] # List your role dependencies here, one per line. Be sure to remove the '[]' above, # if you add dependencies to this list. ansible/roles/tower_demo/tasks/main.yml
New file @@ -0,0 +1,113 @@ --- - name: install pip via yum yum: name: python-pip - name: Install Tower cli pip: name: 'ansible-tower-cli' version: '3.1.8' - name: Configure the tower cli file template: src: "{{ ANSIBLE_REPO_PATH }}/files/tower_cli.j2" dest: "~/.tower_cli.cfg" mode: 0640 - name: copy the license file copy: src: "{{ ANSIBLE_REPO_PATH }}/files/tower_license" dest: "/tmp/tower_license" - name: copy the private key copy: src: "{{ ANSIBLE_REPO_PATH }}/workdir/{{ guid + 'key' }}" dest: /tmp/id_rsa mode: 0640 - name: generate ansible hosts file template: src: "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/files/hosts_template.j2" dest: "/etc/ansible/hosts" - name: Add the license of tower command: | tower-cli setting modify LICENSE '{{ tower_license }}' -u admin -p "{{ tower_admin_password }}" - name: Add tower scm credential shell: | tower-cli credential create --organization="{{ org_name }}" --kind=scm --username=test --password=test --name="{{ scm_cred_name }}" - name: Create Tower project shell: | tower-cli project create --organization="{{ org_name }}" --scm-type=git --scm-branch="{{ scm_branch }}" --scm-credential="{{ scm_cred_name }}" --scm-url="{{ scm_url }}" --scm-update-on-launch=True -n "{{ proj_name }}" - name: create the inventory shell: | tower-cli inventory create -n "{{ inv_name }}" --organization="{{ org_name }}" - name: Add the servers to inventory shell: tower-manage inventory_import --inventory-name={{ inv_name }} --source=/etc/ansible/hosts - name: create the user ssh credential shell: | tower-cli credential create --name="{{ ssh_cred_name }}" --username="{{ user_cred_name }}" --organization="{{ org_name }}" --kind=ssh --ssh-key-data="{{ user_cred_path }}" --become-method=sudo - name: Create the job template shell: | tower-cli job_template create --name 3tier_app_demo --project="{{ proj_name }}" --inventory="{{ inv_name }}" --job-type=run --playbook='{{ playbook_name }}' --machine-credential="{{ ssh_cred_name }}" #- name: Add tower scm credentail # tower_credential: # name: "{{ scm_cred_name }}" # organization: "{{ org_name }}" # kind: scm # username: "testing" # password: "testing" # tower_config_file: "~/.tower_cli.cfg" # #- name: Add tower project # tower_project: # name: "{{ proj_name }}" # scm_update_on_launch: True # description: "ben project" # organization: "{{ org_name }}" # scm_credential: "{{ scm_cred_name }}" # scm_type: "git" # scm_url: "{{ scm_url }}" # scm_branch: "{{ scm_branch }}" # state: present # tower_config_file: "~/.tower_cli.cfg" # #- name: Add tower inventory # tower_inventory: # name: "{{ inv_name }}" # description: "Our Three tier Servers" # organization: "{{ org_name }}" # state: present # tower_config_file: "~/.tower_cli.cfg" # #- name: Add the servers to inventory # shell: tower-manage inventory_import --inventory-name={{ inv_name }} --source=/etc/ansible/hosts # # #- name: Add tower user credential # tower_credential: # name: "{{ ssh_cred_name }}" # organization: "{{ org_name }}" # kind: ssh # username: "{{ user_cred_name }}" # ssh_key_data: "{{ user_cred_path }}" # tower_config_file: "~/.tower_cli.cfg" # #- name: Create tower job template # tower_job_template: # name: "three_tier_app_demo" # job_type: run # inventory: "{{ inv_name }}" # project: "{{ proj_name }}" # playbook: "{{ playbook_name }}" # machine_credential: "{{ ssh_cred_name }}" # state: present # tower_config_file: "~/.tower_cli.cfg" ansible/roles/tower_demo/tests/inventory
New file @@ -0,0 +1,2 @@ localhost ansible/roles/tower_demo/tests/test.yml
New file @@ -0,0 +1,5 @@ --- - hosts: localhost remote_user: root roles: - tower_demo ansible/roles/tower_demo/vars/main.yml
New file @@ -0,0 +1,12 @@ --- # vars file for tower_demo scm_cred_name: 3tierscmdemo proj_name: 3tierdemo scm_url: "https://github.com/prakhar1985/good-ansible.git" scm_branch: "master" inv_name: 3tier org_name: Default ssh_cred_name: "machine_access" user_cred_name: ec2-user user_cred_path: "/tmp/id_rsa" playbook_name: 3tier-good/main.yml