brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [2/4] brooklyn-library git commit: Add sudo to setup of hosts file.
Date Fri, 18 Mar 2016 23:26:00 GMT
Add sudo to setup of hosts file.


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-library/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-library/commit/7e97a26b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-library/tree/7e97a26b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-library/diff/7e97a26b

Branch: refs/heads/master
Commit: 7e97a26b9e79ab8e04c4052d4a2a5658f6f4d62d
Parents: cf65e18
Author: Geoff Macartney <geoff.macartney@cloudsoftcorp.com>
Authored: Fri Mar 11 22:35:36 2016 +0000
Committer: Geoff Macartney <geoff.macartney@cloudsoftcorp.com>
Committed: Fri Mar 11 22:35:36 2016 +0000

----------------------------------------------------------------------
 .../entity/cm/ansible/AnsiblePlaybookTasks.java | 25 ++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-library/blob/7e97a26b/software/cm/ansible/src/main/java/org/apache/brooklyn/entity/cm/ansible/AnsiblePlaybookTasks.java
----------------------------------------------------------------------
diff --git a/software/cm/ansible/src/main/java/org/apache/brooklyn/entity/cm/ansible/AnsiblePlaybookTasks.java
b/software/cm/ansible/src/main/java/org/apache/brooklyn/entity/cm/ansible/AnsiblePlaybookTasks.java
index d22ccab..0589ee7 100644
--- a/software/cm/ansible/src/main/java/org/apache/brooklyn/entity/cm/ansible/AnsiblePlaybookTasks.java
+++ b/software/cm/ansible/src/main/java/org/apache/brooklyn/entity/cm/ansible/AnsiblePlaybookTasks.java
@@ -19,10 +19,10 @@
 package org.apache.brooklyn.entity.cm.ansible;
 
 import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.mgmt.TaskAdaptable;
 import org.apache.brooklyn.api.mgmt.TaskFactory;
 import org.apache.brooklyn.core.effector.EffectorTasks;
 import org.apache.brooklyn.core.effector.ssh.SshEffectorTasks;
+import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.core.task.Tasks;
 import org.apache.brooklyn.util.core.task.system.ProcessTaskFactory;
@@ -35,7 +35,6 @@ import org.yaml.snakeyaml.DumperOptions;
 import org.yaml.snakeyaml.Yaml;
 
 import static org.apache.brooklyn.core.effector.ssh.SshEffectorTasks.ssh;
-import static org.apache.brooklyn.util.ssh.BashCommands.pipeTextToFile;
 import static org.apache.brooklyn.util.ssh.BashCommands.sudo;
 
 public class AnsiblePlaybookTasks {
@@ -110,7 +109,25 @@ public class AnsiblePlaybookTasks {
     }
 
     public static TaskFactory<?> setUpHostsFile(String installDir, boolean force) {
-        return ssh(pipeTextToFile("localhost ansible_connection=local", "/etc/ansible/hosts"))
-            .summary("write hosts file");    }
+        final String hostsFile = "/etc/ansible/hosts";
+        final String tempFile = "/tmp/hosts";
+        String checkInstalled = !force ? "which ansible || " : "";
+        return sshCommands(
+                checkInstalled + " {",
+                sudo("rm -f " + hostsFile),
+                "echo 'localhost ansible_connection=local' > " + tempFile,
+                sudo("mv " + tempFile + " " + hostsFile),
+                "}"
+            )
+            .requiringExitCodeZero()
+            .summary("write hosts file");
+    }
+
+
+    public static SshEffectorTasks.SshEffectorTaskFactory<Integer> sshCommands(String
line, String... lines) {
+        final MutableList.Builder<String> builder = MutableList.<String>builder().add(line);
+        builder.addAll(lines);
+        return ssh(Strings.join(builder.build(), "\n"));
+    }
 }
 


Mime
View raw message