Skip to content

Add creation of /etc/ansible hosts during install.#18

Closed
geomacy wants to merge 1 commit intoapache:masterfrom
geomacy:ansible-host-file
Closed

Add creation of /etc/ansible hosts during install.#18
geomacy wants to merge 1 commit intoapache:masterfrom
geomacy:ansible-host-file

Conversation

@geomacy
Copy link
Contributor

@geomacy geomacy commented Mar 11, 2016

This allows replacement of the command form

ansible-playbook -i "localhost," -c local whatever

with

ansible-playbook whatever

and also supports the possibility that playbooks can modify the hosts file e.g. by adding additional groups that included roles require.

For example the following playbook modifies the hosts to add a tomcat-server group, in order to install an example ansible from the github examples repo.

 name: multi
 location:
   red1
 services:
 - serviceType: brooklyn.entity.basic.SameServerEntity
   name: Entities
   brooklyn.children:

   - serviceType: org.apache.brooklyn.entity.cm.ansible.AnsibleEntity
     id: bootstrap
     service.name: crond
     playbook: bootstrap
     playbook.yaml: |
         ---
         - hosts: localhost
           tasks:
           - shell: printf "[tomcat-servers]\nlocalhost ansible_connection=local\n" >> /etc/ansible/hosts
           - file: path=/etc/ansible/playbooks state=directory mode=0755
           - get_url: url=https://github.com/ansible/ansible-examples/archive/master.zip dest=/tmp/master.zip mode=0440
           - command: unzip -o -d /etc/ansible/playbooks /tmp/master.zip

   - serviceType: org.apache.brooklyn.entity.stock.BasicApplication
     start.latch: $brooklyn:component("bootstrap").attributeWhenReady("service.isUp")
     brooklyn.children:
     - type: org.apache.brooklyn.entity.cm.ansible.AnsibleEntity
       name: test
       service.name: tomcat
       playbook: tomcat
       playbook.yaml: |
           ---
           - hosts: localhost
           - include: /etc/ansible/playbooks/ansible-examples-master/tomcat-standalone/site.yml
             vars:
                 http_port: 8080
                 https_port: 8443
                 admin_username: admin
                 admin_password: secret

This allows replacement of the command form

   ansible-playbook -i \"localhost,\" -c local  whatever

 with

   ansible-playbook whatever

 and also supports the possibility that playbooks can modify the hosts file e.g. by adding additional groups that included roles require.

 For example the following playbook modifies the hosts to add a tomcat-server group, in order to install an example ansible from the github examples repo.

 name: multi
 location:
   red1
 services:
 - serviceType: brooklyn.entity.basic.SameServerEntity
   name: Entities
   brooklyn.children:

   - serviceType: org.apache.brooklyn.entity.cm.ansible.AnsibleEntity
     id: bootstrap
     service.name: crond
     playbook: bootstrap
     playbook.yaml: |
         ---
         - hosts: localhost
           tasks:
           - shell: printf "[tomcat-servers]\nlocalhost ansible_connection=local\n" >> /etc/ansible/hosts
           - file: path=/etc/ansible/playbooks state=directory mode=0755
           - get_url: url=https://github.com/ansible/ansible-examples/archive/master.zip dest=/tmp/master.zip mode=0440
           - command: unzip -o -d /etc/ansible/playbooks /tmp/master.zip

   - serviceType: org.apache.brooklyn.entity.stock.BasicApplication
     start.latch: $brooklyn:component("bootstrap").attributeWhenReady("service.isUp")
     brooklyn.children:
     - type: org.apache.brooklyn.entity.cm.ansible.AnsibleEntity
       name: test
       service.name: tomcat
       playbook: tomcat
       playbook.yaml: |
           ---
           - hosts: localhost
           - include: /etc/ansible/playbooks/ansible-examples-master/tomcat-standalone/site.yml
             vars:
                 http_port: 8080
                 https_port: 8443
                 admin_username: admin
                 admin_password: secret
@geomacy
Copy link
Contributor Author

geomacy commented Mar 11, 2016

Needs more work - sudo

@geomacy geomacy closed this Mar 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments